# Mathematically combine multiple prom metrics with matching labels

**URL:** <https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758>\
**Category:** Prometheus\
**Tags:** expressions, promethues\
**Created:** [June 25, 2024, 9:34am UTC](https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758 "2024-06-25T09:34:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tg44](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tg44](https://community.grafana.com/u/tg44)\
**Post date:** [June 25, 2024, 9:34am UTC](https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758/1 "2024-06-25T09:34:32Z")

</div>

Hy!

I have 2 prom metrics `temperature` and `humidity`. Both of these have a label `sensor` (like “livingroom”, “kitchen” etc. in them).

Can I use any features in grafana to calculate a heat index (for a dummy example something like `4 + 3*temperature + 4*humidity - 2.5*temperature*humidity`, but the actual equation has 16 additions in it) for each temp-hum pair with matching sensor labels?

(I tried expressions, but as I understand it can’t handle if A and B has multiple series in them. I tried transformations, and I could successfully join A and B but I don’t have any freeform math input to work with those fields. It seems like a not so hard problem.)

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/59065_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [June 25, 2024, 12:19pm UTC](https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758/2 "2024-06-25T12:19:07Z")

</div>

can you not do the equation in your query?

---

<div class="post-metadata">

**Author:** ![tg44](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tg44](https://community.grafana.com/u/tg44)\
**Post date:** [June 25, 2024, 12:34pm UTC](https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758/3 "2024-06-25T12:34:14Z")

</div>

You mean I should export the HI itself as a separate metrics? This is my plan B but ideally I would compute it live.

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/59065_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [June 25, 2024, 12:39pm UTC](https://community.grafana.com/t/mathematically-combine-multiple-prom-metrics-with-matching-labels/124758/4 "2024-06-25T12:39:17Z")

</div>

there are binary option transforms, but as binary implies, you can only use two fields at a time…

4 + 3_temperature + 4_humidity - 2.5_temperature_humidity

step 1: 3\*temperature  
step 2: 4 + result of step 1  
step 3: 4 \* humidity  
step 4: result of step 2 + result of step 3  
step 5: temp \* humidity  
step 6: 2.5 \* step 5  
etc.
