How to count events(errors) on selected period? (Loki/Prometheus)

(Grafana newbie here.)

Really frustrated about simple counting of particular events during selected time.
I’ve got a simple dashboard, where I have log lines from LOKI (on the screenshot - filtered by “ERROR” keyword), some graphs, etc.

I want to count (just count, not average, etc.) my app’s errors during given time interval.
5m, 30m or user selected (with mouse on graph).

I’ve created a variable ($var_selected_interval, type=interval, Auto=ON) and used it in a panel:

So… as we can see on the 1st screenshot Errors count in the logs really differs from the “calculated”.
What this " 1.9 " errors mean?
1.9 (even 19) in selected by user 5 minutes period? Wrong!
1.9 per second?.. Doubtfully
So, I need only a count. Count all error lines in my log.

I have tried count_over_time, sum, rate, etc… Nothing helps.

What I am doing wrong?
Please, help.

Hmmm… looks like I should use " $__range" variable, right?

do you have TOTAL selected in the stats value setting?

Not sure, where to find this “TOTAL” option…

HI. I got this to work in a similar use case. I wanted to tally up the total number of lines where a specific issue occurred. Here is what I did.

One thing I ran into is that when the interval was very large the counts were not accurate, it was like it was dropping dome of the entries. This is why I set the max data points option, once I did that it was better unless I went to a really large interval.

Hope this helps!