v.WindowPeriod not available when displaying two queries

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.

Second image:

Hello @johnnyfleet,
You don’t actually select the windowPeriod with the drop down only the start and stop times.
The value of this windowPeriod variable is calculated by analyzing the duration of the Flux query it is used within. Queries that fetch data from a longer time range will have a larger v.windowPeriod duration.

You could maybe use flux variables in your dashboard though for this. Use and manage dashboard variables | InfluxDB Cloud (TSM) Documentation

Hi - You’re right, I don’t usually select the window period, but whatI find is it helps to provide a sensible grouping depending ont he start and stop times.

Hi @Anaisdg - thanks for the follow up.

Yes thats the point I think I’m making, I assume it is auto calculated. However in the second query it doesn’t seem to be recognised, so the granularity is waaayy to fine.

For example, if I pull back the last 2 days the performance is fine, but if I try and pull back YTD its a very long query. Thats because the granularity isn’t auto adjusting based on the start & stop times as I’d expect.

Any suggestions greatly appreciated.