Math expression with Nan values

I am currently using Grafana v10.4.1

I am trying to achieve calculation through Math Expression based on the results of others Queries.

Example : ($QueryA +$QueryB)/($QueryA + $QueryC + $QueryB)

The queries are doing sums.
Example : QueryB:

SELECt sum(duration_hours)
from prsm_edhid_teeptrak_dw.eoee_rawdata
where issue_type_Level1 =‘Unknown’ and machine = ‘UK-ALFA17’
and $__timeFilter(start_dt_local_tz)

It can happen that this sums returns Nan values

When some queries return Nan values the Math expression return Nan as well.

In my example above if QueryB return Nan the Math expression will return Nan

I would like the Math expression to consider QueryB as 0 value instead of Nan so that the Math expression does not return Nan. How could I perform this ?

Thanks for your help

Hey,
What do you think of the coalesce function, there?
Could look likes:

SELECT COALESCE(SUM(duration_hours), 0)
from ...
...
...
1 Like

Hello codi639,
This is perfect ! Simple to apply and solving my issue.
Many thanks !