Hello @Sander,
Welcome!!
You can do this by performing applying a timeShift() function and joining the results to compare the values before and after/ get values on the same row:
Please note that you would have to:
- query for your data, store result in a variable (i.e. original)
- shift forward once, store the result in a variable (i.e. forward)
- join forward and original, store the result in a variable (i.e. first_join)
- repeat with shifting back
You also might want to try pivoting().
from(bucket: "noaa")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "average_temperature")
|> filter(fn: (r) => r["_field"] == "degrees")
|> filter(fn: (r) => r["location"] == "coyote_creek")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> limit(n: 3)
|> map(fn: (r) => ({ r with X: 1.0 }))
|> cumulativeSum(columns: ["X"])
|> drop(columns: ["_start", "_stop", "_measurement"])
|> pivot(rowKey:["_field"], columnKey: ["X"], valueColumn: "_value")
This approach could work if you window your data so that each table only returns 3 values. Then you could apply your conditional mapping?