Expression query in Stat panel issue

Hi,

I saw this https://localhost:3000/t/expression-query-in-stat-panel/57547

which talks about expression query in Stat panel.

And I’m doing almost the same case with using Expression function.

My data source is from Cloudwatch and I need to calculate the success rate of invoking API, so I had two queries, one was the number of calling API, and the other was the number of successfully executing the API, therefore I used Expression function to division two numbers to calculate the successful rate.

but there’s the problem, my two queries refId were named A and B, so I wrote “$B/$A*100” and it was not work, even I wrote only ‘$A’ it was wrong either.

I’ve followed the official document->Write expression queries | Grafana documentation

But I couldn’t figure out why It was wrong!


This pic shows that only two queries are work!


You can see the pic above and it occurred error when I add new Expression.

Is syntax like “$B/$A*100” wrong? Or it can’t get the value of refId A and refId B?

Your expression C looks fine, but I noticed that in my screenshot (Grafana 9.0.7), it says
C (Expression)
while yours says
C (_expr_)

What version of Grafana are you using? Are you certain that the values returned in A and B are integers or floats (and not strings)?

1 Like

Hi sir, thanks for your reply.

I thought the cases between us were different!
My data source was from CloudWatch log, and I used log insight syntax to count the total number of occurrences of the “statusCode” field, and I thought it was int type.

Could you try the case that the data source is from CW log?
Thank you so much!!!

@grant2
Hope you can assist me with this feature which queries from the result of CW insight.

Thank you sooooooo much!!!

1 Like

I do not have Cloudwatch as a datasource.