I want to change the columns of three data series and I get this error:
rename error: column "Home own consumption from PV" doesn't exist
The original names of the data contain spaces. Is there a solution for this?
from(bucket: "telegraf")
|> range(start: -10m)
|> filter(fn: (r) => r["_measurement"] == "modbus")
|> filter(fn: (r) => r["_field"] == "Home own consumption from PV" or r["_field"] == "Home own consumption from battery" or r["_field"] == "Home own consumption from grid")
|> rename(columns: {"Home own consumption from PV": "PV"})
Hi @Cavekeeper,
So this is based on the structure of InfluxDB’s tables:
As you can see _field contains your field names. There are two ways to solve this:
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> rename(columns: {"Home own consumption from PV": "PV"})
or use a conditional map. I personally would suggest doing the first then writing the data to a new measurement before running any further calculations against it:
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> rename(columns: {"Home own consumption from PV": "PV"})
Like so:
import "influxdata/influxdb"
from(bucket: "C02-Demo")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "mqtt_consumer")
|> filter(fn: (r) => r._field == "co2" or r._field == "eCO2")
|> rename(columns: {"Home own consumption from PV": "PV"})
|> influxdb.wideTo(bucket: "bucket")
1 Like
Many thanks @Jay_Clifford
This was the solution:
The correct order of the lines is important.