How can i turn no data to zero in Loki

Hi all , Im looking for a way to turn the null/no data return to zero in logql. Im trying to get the percent of the request just like

sum(count_over_time({app="xxx"}|="{"|json|route="POST /api/a" , status=~`200|400|401|403|429|404` [1m])) / sum(count_over_time({app="xxx"}|="{"|json|route="POST /api/a" [1m]))

But when there is no 200|400|401|403|429|404 of /api/a the return of sum(count_over_time({app="xxx"}|="{"|json|route="POST /api/a" , status=~200|400|401|403|429|404 [1m])) is no data ,and i wanna turn it to zero. So the total result can be 0%

This is a good question, I’m not sure if this is currently possible but will ask the team for options here!

I am also interested in this. Any way to make a logql query return zero when theres no data ?

It’d be really helpful to get an answer on this. Now that we can alert based on Loki LogQL metric queries, sending alerts based on error logs seems like a common use case. But if your query returns no data when there are no error logs, it’s impossible to get your alert to work properly.