Hide card on dashboard when it returns zero or null results

Hello everyone,

I'm using filters on a dashboard to switch from one subcategory of data to another. I want the cards connected to the first subcategory to disappear when the second subcategory is selected, and vice-versa. This does work using the "Hide card when there is no results" toggle, but not when the result is 0 (e.g on cards with a "Count rows" or "Distinct values of" summary). I've tried to work around this by using a custom expression CountIf(notnull([ID])) in order to make the card return "null" instead of 0, but the card is still displayed on the dashboard. Is there a way to turn "0" or "null" into "No result"?

Thanks!

There may be other options, but the thing that immediately comes to mind is turning the card into a SQL questions and adding another condition to the query. This depends on your DB and the data structure but if there is something that's equivalent to the "HAVING" clause you could do something like:

select category, count() as item_count
from items
where 1=1
group by category
having count(
) >0

1 Like

That worked using count(*)! Thank you very much :slight_smile:

1 Like

You're quite welcome!

If using a SUM() function in your query, you can skip null values using COALESCE(SUM(column_name), 0)

SELECT
  COALESCE(SUM(`amount`),0) AS `sum`
FROM ...