Is there any way to include "Null" values in a Grafana variable?

Hi,

I have a query in Postgres which returns the following values: [NULL, A, B, C, NULL]

And I’ve also implemented a variable to get specific values from this query. The problem is that the possible values for this variable are A, B and C. Currently, when I select “All” option, values “A”, “B” and “C” are returned, but not NULL values. I’d like to obtain NULL values too when my variable has the “All” options selected. Is this possible?

Thanks

2 Likes

I’m having the same problem here :frowning:

1 Like

Hi,
I found a solution for this trouble but I don’t sure about is this best practice. I did like this. try add null value your query result and add a condition for that check null value. If you learn more about in clause click here.

You have to add your dashboard query extra null statement because postgresql doesnt bring null values when you queried like with in $VariableA. You must add for your null values or IDD."ColumnA" is null
I did it as follows.

VariableA:
(SELECT DISTINCT "ColumnA_desc" as __text, "ColumnA" __value FROM yourSchema."YourTable" D WHERE "ColumnA_desc" IS NOT null) union all (select ‘(Empty)’ as __text, ‘#####’ as __value) ORDER BY 1 ASC

Dashboard:
SELECT IDD."CreateTime" AS time, IDD."ColumnA" AS value, IDD."ColumnA_desc" AS metric FROM yourSchema."YourTable" IDD WHERE
(case
when (’#####’) in ($VariableA) then IDD.“ColumnA” IN ($VariableA) or IDD.“ColumnA” is null
else IDD.“ColumnA” IN ($VariableA)
end)