How do I set dynamically every on aggregateWindow?

Hi,
I would like to change every on aggregateWindow dynamically.
for example, range on Dashboard is

  • less than 1hour : every : 10s
  • 1hour to 3hours : every : 1m
  • 3hours to 1day : every : 10m
  • 1day to 1week : every : 1h

However, I cannot find solution.
How do I set it?
My script is here.

from(bucket: “my_bucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “Point”)
|> filter(fn: (r) => r["_field"] == “Target”)
|> aggregateWindow(every: 10m, fn: last, createEmpty: false)
|> difference()
|> yield(name: “last”)

You could compute delta= v.timerangestart - v timerangestop in a variable at the beginning. Note that, one of the 2, at least in the past, was a duration, so you have to convert it to a time (or an integer?) I don’t remember if it was start or stop but you’ll figure it out.
Then you make a sequence of if-else. Something like:

Test = if delta <1h then… Else if delta < 3h then…
I don’t remember exactly the if structure and i am on the phone. Anyway, we do something similar somewhere so it is doable

Then you replace your 10m in your script inside of the aggregate window with the variable Test
Good luck

Hi, MzazM,
Thank you for your advice!
I could set variable time in every.
I share the solution.
Every is 1m when range is less than 1h.
When range is over 1h, every is 10m.

from(bucket: “my_bucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “Point”)
|> filter(fn: (r) => r["_field"] == “Target”)
|> aggregateWindow(every:
if int(v: v.timeRangeStop) - int(v: v.timeRangeStart) < 60 * 60 * 1000000000 then 1m
else 10m, fn: last, createEmpty: false)
|> difference()
|> yield(name: “last”)