Hello!
We are trying to calculate a specific value but it doesn’t work. Our data gives us an accumulated value which we want to manipulate to only show data with todays timestamp. But we need yesterdays data to be subtracted or the first value of today set to 0. Both ways would work.
So basically we are trying to show todays energy consumption. Therefore we need to display the difference between the current value and the first of the day.
Example:
value = value.rightnow - value.atMidnight
Our implementation:
from(bucket: "ecobucket")
|> range(start: today())
|> filter(fn: (r) => r["_measurement"] == "mqtt_consumer")
|> filter(fn: (r) => r["_field"] == "ENERGY_Today")
|> filter(fn: (r) => r["host"] == "telegraf")
|> filter(fn: (r) => r["topic"] == "PowerMeter/001/power/SENSOR")
|> map(fn: (r) => ({ r with _value: r._value - r._value.today() }))
|> yield(name: "last")
Thank you!