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.

hello @Celeste,
That’s strange. On the forums it shows that you wrote this question
13d ago not in feburary. Why was it put on hold?

I am not sure. I submitted this February and could’t post it. I just got this message below. Then 13 days ago my account was no longer on hold and it was posted. Over a month is kind of a long time to put a user on hold for no reason. Perhaps you could bring this up with your team?
Thank you again!

Hello,

This is an automated message from InfluxData Community Forums to let you know that your account has been temporarily placed on hold as a precautionary measure.

Please do continue to browse, but you won’t be able to reply or create topics until a staff member reviews your most recent posts. We apologize for the inconvenience.

For additional guidance, refer to our community guidelines.

@Celeste ahhh Its possible you tried to ask a question on the one day when we temporarily disabled commenting to deal with some spam attacks. I’m so sorry about that!

Oh, ok! Got it thank you.

1 Like