Hi there, I have a bucket full of temperature sensors from a weather station. I’m trying to display year over year comparisons, one metric showing temperature for the chosen window, and the other showing the same data but from 1 year ago.
The query below works fine with one exception, it doesn’t perform the aggregate window properly.
import "date"
lastYear = from(bucket: "sensors")
|> range(start: date.sub(d: 1y, from:v.timeRangeStart), stop: date.sub(d: 1y, from:v.timeRangeStop))
|> filter(fn: (r) => r["_measurement"] == "weather")
|> filter(fn: (r) => r["_field"] == "temperature_C")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> timeShift(duration: 1y, columns: ["_start", "_stop", "_time"])
|> yield(name: "lastYear")
thisYear = from(bucket: "sensors")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "weather")
|> filter(fn: (r) => r["_field"] == "temperature_C")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "thisYear")
It seems to be due to v.WindowPeriod not being available when I have the last year metric included.
I’ve noticed in the editor that if I have just the this year metric (remove last year) then the v.windowPeriod variable appears as an option on the right (see first image). But when I add back in, it immediately goes.
I ideally want it to use the v.WindowPeriod tag so that I can display on a dashboard with the flexibility to choose the period - and have influx automatically use a sensible windowperiod for performance.
I have a second image showing the missing window period but can’t upload as new user. But you should be able to recreate by pasting the above query into a script editor window.
Running a local instance of Influx OSS: v2.71
Any guidance would be greatly appreciated.