IF-ELSE-CONDITION in the query editor

Dear sir / madam!

Is there any way to implement IF-ELSE-CONDITION (or something similar) in the query editor depending on the value of the variable?

Something like this:

if ($__range <= 15m) then

SELECT mean("value") FROM "autogen"."tssamples" WHERE ("paramName" = 'current')
AND $timeFilter **GROUP BY time(1s)**, "paramName" fill(none) ORDER BY time DESC

end_if

SELECT mean("value") FROM "autogen"."tssamples" WHERE ("paramName" = 'current')
AND $timeFilter **GROUP BY time($__interval)**, "paramName" fill(none) ORDER BY time DESC

end_else

Thank you!

1 Like

You can use variable names within your queries, so provided the query language
you are using (which is dependent on the backend data store you have chosen)
supports conditional statements, then yes, this can be done.

Grafana itself has no built-in support that I know of for this.

Antony.

I’m using using MySQL and from what I’ve read online, use of conditional statements is somewhat restrictive…

Where you able to find any workarounds?

Thanks!