Hi experts,
I try to calculate the sum of two values from two independent measurements using Flux on an InfluxDB 2.7. Currently,I am trying to re-use code where I successfully summed values from ONE measurement:
from(bucket: "Stromverbrauch")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "meas1" or r["_measurement"] == "meas2")
|> filter(fn: (r) => r["_field"] == "data1" or r["_field"] == "data2") # note: data1 from meas1, data2 from meas2
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({r with _value: r.meas1 + r.meas2}))
|> drop(columns: ["meas1", "meas2""])
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: true)
|> yield(name: "mean")
This query yields no data, which is due to the fact that the is a time difference of 2 seconds between equivalent data points from meas1 and meas2.
Reading the Flux documentation I figured that it should be possible to use timeShift(...)
to move a data point. However, I am not sure how this could be done in my scenario, where I only want to shift ONE of the two data sets.
So maybe you know how to achieve my goal? Thanks in advance