Expression in stat, issues with dividing two different measures with influxql

Hi, I am a newbie and I started using Grafana by myself, so sorry if this question sounds stupid.
I am trying to achieve a stat dashboard that shows the performance of a heat pump, I want to show three numbers
-the energy consumption
-the electricity consumption
-the ratio between the two (energy/electricity)

I am using influxdb and influxql. the energy consumption and electricity are calculated measures (there is a counter that increase over time and the difference between two periods is the consumption). the query that I am using are the following:


The first two numbers are the sum of the consumption of the last two days, I used a calculation “Total”. The ratio is simply calculated as $A/$B and the result is infinite.
it looks like that the calculation adds up the single points ratio, when the $B query is zero it goes to infinite. what I want to achieve instead is having a ration that works like the following formula sum($A)/sum($B). Is it feasible?

Hi,

If no one else will come and say how to do that Influx-style (and your Grafana version is at least 11.3.0), you can do the following:

  1. Use Reduce transformation (Mode = Series to rows; Calculations: Total) which will calculate the total you’ve marked with red line on your screen.
  2. Use Transpose transformation, so that your rows become columns
  3. Use Add field from calculation transformation with Mode set to binary operation and divide one number by another.
  4. Use Last* calculation instead of Total

With settings like this you should be fine.

I’ll repeat - use this only if no one else comes with better solution (transformations are often last-ditch efforts but I know nothing of Influx :smile:)

2 Likes

Hi,
that’s awesome! I am more interested in using Grafana then Influx, thank you very much for your help, really appreciated.
Francesco

1 Like