Conditionally assign Flux variable - syntax error

I’m trying to conditionally assign a value to the variable START as part of a Flux query:

WINDOW = 1d
START = if WINDOW == 1d then today() else 2022-01-01

This results in the following error:

unsupported binary expression duration == duration

What is the correct syntax/approach?

Hello @cville,
I’m not sure why that isn’t supported.
Can you please create an issue here?

I found this workaround though

import "date"
mywindow = date.sub(d: 1d, from: now())
mystart = if mywindow ==  date.sub(d: 1d, from: now()) then today() else 2022-01-01

Btw what are you using Influx for? I’d love to learn more about what youre doing with it. Thanks and I hope you have a good day.

Thank you @Anaisdg.

I will report this issue as requested; I just noticed that I’m one minor release behind, so will have to upgrade first (2.2.0 to 2.3.0).

I will try your workaround later.

As to what I’m using InfluxDB for: I’m a retired Enterprise Architect and restarted coding - as a hobby - after a 30 year hiatus upon my retirement in 2011. The code I had an issue with, is part of my PV (solar panels) Grafana dashboard, one of the many I’m using.

Last year I started migrating my code to a new ProxMox server and am slowly converting my code and queries from InfluxDB 1.8 to InfluxDB 2. Flux, though powerful, has a steep learning curve, partially caused by the lack of sophisticated debugging capabilities/error messages.

Thanks again for your support.