Hi, I am plotting on Grafana using flux.
I am having trouble summing a value across all my devices while keeping the _time column.
For example, below is my working code for displaying battery state of charge. This displays all the devices in a separate lines. I would like to sum them. For example, if I have three devices and one is at 30%, one is at 80% and another at 100% the plot would read 210.
The problem is that when I use sum() it eliminates my _time column.
I attached a csv.
Thank you.
Code:
collectionInterval = 5.0
from(bucket: “Bytes”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “battery”)
|> filter(fn: (r) => r._field == “bms_soc”)
|> aggregateWindow(every: duration(v:(uint(v: v.timeRangeStop) - uint(v: v.timeRangeStart))/uint(v: 800)), fn:mean)
|> pivot(rowKey:[“_time”], columnKey: [“_field”], valueColumn: “_value”)