Count how many times reaching a certain level

Hi, I am using Influx 1.8 with Grafana and I am trying to count how many times a measure reached a certain value. In the image example, I get one point every minute and I am aiming to count how many times the measure dropped to zero → 5 times. Tried to look into functions, searched similar examples and used Derivative function but cannot get exact results.

Hello @e.gas,
Welcome!
Have you tried using the stateCount() function?

Alternatively you could conditionally map a level and count that: