Expression query in Stat panel

  • What Grafana version and what operating system are you using?
    Grafana 8.1.5; host OS unknown

  • What are you trying to achieve?
    In a Stat panel, I have two queries that query AWS CloudWatch. The two queries return the total number of things and the total number of successful things. These two queries perform as I expect and show results as I expect.

I want to create a third query to show percentage of failed things as ($total - $success) / $total * 100. As soon as I add this Math query, the entire panel, including the two queries above that had previously worked, stop returning results.

Not working:

  • What happened?
    All queries returned 0

  • What did you expect to happen?
    Existing 2 queries to continue to return data, third query to do calculations from the first 2 queries

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No

  • Did you follow any online instructions? If so, what is the URL?
    No

EDIT: Since the screenshots were resized, the expression in the third spot is “($Total - $Success) / $Total * 100” and it is a Math operation.

Welcome to the Grafana community.

Instead of using the alias names ($Total and $Success), try removing those names and use $A and $B, just to see if it works.

Here is what I got using only A and B:

Here is what I got using Total and Success as alias names, but using $A + $B for the expression:

And here is what I got using $Total + $Success:

Obviously, the middle option above is closest to what you want.

You could then do a Display Name override to get what you want:

Thank you, Grant. Regrettably I’m not seeing the same results. Here’s what I was able to do when I renamed my queries back to “A” and “B” and made a math expression in query “C”. Queries A and B work fine and show correct data right up until Query C is added, which is when all three queries show ‘0’.

Are there any known issues in Grafana 8.1.5 that would cause this? I don’t own the application, but if I can point to a fix I might be able to get the company to upgrade.

I tested on the latest version of Grafana in a Docker image and it appears to be working correctly there. (Or, at least, more correctly.) I’ll have to see if I can get I.T. to upgrade our instance.

1 Like

I’m also facing similar issue.
I’ve two queries that are fetching information from Jira related to Success and Failure and I want to calculate Success percentage but simple math expression not working for me


.