Summing a value across all my devices while keeping the _time column.

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”)

Hello @Celeste,
Yes this makes sense because there is one _time value per _value. If you sum them there isn’t an obvious choice for which time value should be retained. What do you imagine the ouptut would look like?

I don’t see a CSV can you please attach it again?

I would also try using findrecord() function findRecord() function | Flux Documentation
and retaining a time stamp value of your choice and then creating a new column with that value with:
map() map() function | Flux Documentation

Hi, thank you Anais. I submitted this in February and Influx put my account on hold. It took Influx two months to post this to the forum. I found a different solution but I will keep findRecord() in mind.