Count active prometheus alerts

I’m having trouble counting alerts fired by prometheus in a single stat panel. This is my query:

count(ALERTS{job="myjob", alertstate="firing"} == 1)

But there is a problem. If no alert is active (“firing”), prometheus returns no data. Not 0, indeed no data. This causes my single stat panel to show the most recent value, instead of 0. Can I somehow “map” no data to 0?
I mapped null -> 0 but this doesn’t work.

Don’t think there is a way, so you query returns no data points?

Yep my query returns no data points, but only in the case there are no alerts. I’m not a Prometheus expert, but alerts behave a little different than other time series. So I can use count() on alerts, but only if they currently exist.

I think you have the right concept in mind. You might want to try this:

count by(alertstate,job) (irate(ALERTS{job=“yourjob”, alertstate=‘firing’}[72h]))

This should return all of jobs that have alerts firing for the last 72 hours and a tally.