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

**URL:** <https://community.grafana.com/t/expression-in-stat-issues-with-dividing-two-different-measures-with-influxql/139682>\
**Category:** Dashboards\
**Created:** [January 6, 2025, 8:53pm UTC](https://community.grafana.com/t/expression-in-stat-issues-with-dividing-two-different-measures-with-influxql/139682 "2025-01-06T20:53:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![francescovanin](https://avatars.discourse-cdn.com/v4/letter/f/7cd45c/32.png) [@francescovanin](https://community.grafana.com/u/francescovanin)\
**Post date:** [January 6, 2025, 8:53pm UTC](https://community.grafana.com/t/expression-in-stat-issues-with-dividing-two-different-measures-with-influxql/139682/1 "2025-01-06T20:53:38Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/9/e/9e6de9a34a6baaa270101e2c0487e089d31c5138.png)  
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?

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [January 7, 2025, 3:19pm UTC](https://community.grafana.com/t/expression-in-stat-issues-with-dividing-two-different-measures-with-influxql/139682/2 "2025-01-07T15:19:45Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/d/3/d32bb613c21b6be5cdf63b13198d32a1023d9840.png)

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 😄)

---

<div class="post-metadata">

**Author:** ![francescovanin](https://avatars.discourse-cdn.com/v4/letter/f/7cd45c/32.png) [@francescovanin](https://community.grafana.com/u/francescovanin)\
**Post date:** [January 7, 2025, 8:58pm UTC](https://community.grafana.com/t/expression-in-stat-issues-with-dividing-two-different-measures-with-influxql/139682/3 "2025-01-07T20:58:37Z")

</div>

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