# Query breaks when host variable is used

**URL:** <https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762>\
**Category:** Zabbix\
**Tags:** query-help\
**Created:** [January 24, 2024, 6:39pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762 "2024-01-24T18:39:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 24, 2024, 6:39pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/1 "2024-01-24T18:39:34Z")

</div>

![Dashboard](https://us1.discourse-cdn.com/grafana/original/3X/7/e/7e8de5212a3a377c7ca11e889678036da9bdd82f.jpeg)

I am trying to create a panel to show the temps of a switch.

The switch sends those temps as Celsius, I want to show them as Farenheit.

The query to get the metric works fine, even with a host variable. That query is “A”.

Then I create an expression to recalculate the Celsius value to Fahrenheit:  
Simple expression: $A \* 1.8 + 32

The second I add the expression and include the query variable $A the data panel goes to NO Data, and I get an error flag: 2 items dropped from union(s): [“$A \* 1.8”: (1.8: {}][“$A \* 1.8 + 32”: {})]

If I use the actual host name instead of a variable, I have NO problem everything works fine. I could create a copy of the dashboard for every device, but I would rather just use a host selection dropdown so we maintain one dashboard instead of many.

The picture above shows the panel. There are three temps, the top value is not working because of the host variable being used in query “A”. The same would happen to the other two values if I used the variable in their queries (C and E)

I feel like I must be missing something basic… I cannot believe that this product would not be able to include/pass a host variable in its queries?

Can anyone offer a solution?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [January 24, 2024, 7:54pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/2 "2024-01-24T19:54:08Z")

</div>

> [@msulewski](#):
>
> Simple expression: $A \* 1.8 + 32

It may looks simple, but it is not, because you are missing time dimension (it is query result, which may be timeseries with multiple values):

> [@Addition of queries via Expression option not working](https://community.grafana.com/t/addition-of-queries-via-expression-option-not-working/112256/2):
>
> What’s looks like a simple math (A+B) is not so simple. Start simple math: 10 (result from query A) + 10 (result from query B) = 20 (expected result from math expression $A+$B) Actually, result from query is timeseries (see query config Format as: Time series) - there is list of values and each value represent some value in time, so it can be: 10 (result from query A at 2024-01-01 00:00:00) + 10 (result from query B at 2024-01-01 00:00:00) = 20 (expected result from math expression $A+…

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 24, 2024, 8:05pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/3 "2024-01-24T20:05:51Z")

</div>

Thanks. But the query itself is not the issue… It is the fact that it breaks when a Hostname variable is introduced into query “A” AND an Expression (“B”) is added to recalculate the value of “A” If I use the actual Hostname (not a variable), it works fine. If I change the host name to a variable the query gets broken when an expression (“B”) is added.

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [January 24, 2024, 10:03pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/4 "2024-01-24T22:03:07Z")

</div>

Yes, first sort query A (so remove/disable expression, which is misleading error here, because that’s just consequence of query A error)  
Use query inpector and make sure that variable generates proper syntax with right variable formatting: [Variable syntax | Grafana documentation](https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/)

---

<div class="post-metadata">

**Author:** ![bernardolankheet](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/bernardolankheet/32/38509_2.png) [@bernardolankheet](https://community.grafana.com/u/bernardolankheet)\
**Post date:** [January 25, 2024, 8:53am UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/5 "2024-01-25T08:53:59Z")

</div>

Perhaps you can try to perform this conversion from Celsius to Fahrenheit in Zabbix, using a calculated item, then consume this item in the Grafana panel.

This step would be simpler and faster, leaving all the calculations on Zabbix’s side and just visualization in Grafana.

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 25, 2024, 2:39pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/6 "2024-01-25T14:39:56Z")

</div>

Thank you. This is just ONE example. The problem is not in the calculation, since the calculation works until a Hostname variable is introduced. It is with how Grafana uses it’s own variables in queries, expressions, and layers. Maybe this is specific to the Zabbix plugin? This is key to templating dashboards. It not only affects calculations, but whether the same dashboard item can work across multiple devices.

Thanks!

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [January 25, 2024, 3:42pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/7 "2024-01-25T15:42:24Z")

</div>

How are you using the variable in your query

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 25, 2024, 4:51pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/8 "2024-01-25T16:51:15Z")

</div>

I spoke with the good folks at Grafana this morning and showed them my problem.

They agreed that what I am doing should (in theory) work.

They are going to talk amongst themselves and see if they can come up with a solution. I will post back here after I hear from them.

---

<div class="post-metadata">

**Author:** ![bernardolankheet](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/bernardolankheet/32/38509_2.png) [@bernardolankheet](https://community.grafana.com/u/bernardolankheet)\
**Post date:** [January 25, 2024, 4:59pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/9 "2024-01-25T16:59:02Z")

</div>

It’s not really wrong, this way it should work, if you need a faster solution, try doing it using Zabbix or even using Gratana’s transform function

---

<div class="post-metadata">

**Author:** ![nedra](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@nedra](https://community.grafana.com/u/nedra)\
**Post date:** [January 26, 2024, 9:14am UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/10 "2024-01-26T09:14:09Z")

</div>

I have same issue [msulewski](https://community.grafana.com/u/msulewski), has it been resolved?

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 26, 2024, 2:08pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/11 "2024-01-26T14:08:25Z")

</div>

Our group and Grafana are meeting up next week. I will post back if we have a solution.

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 26, 2024, 10:28pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/12 "2024-01-26T22:28:38Z")

</div>

Met with Grafana. It is a confirmed issue at this point that the Zabbix plugin does not parse the Host variable in Grafana.

They are escalating to see if they can come up with a fix.

We did come up with a work around.

1: Remove any expressions.  
2: Create a new Panel, Select “Dashboard” as the data source.  
Select the dashboard that has your queries that were having the problem.  
It will show you all the queries from that dashboard.

You can now do transformations on those queries.

in my case I had to do two transformations on each query to get the calculation I was trying to do (Query result \* 1.8 + 32).

 ![Transorm](https://us1.discourse-cdn.com/grafana/original/3X/d/f/df13ebea3daf0e7513fc870e083acf3394a19c63.jpeg)

In the first item I had to select the first query, the operator (\*), and the value (1.8).  
I had to give it a unique alias that would then be used in the next step.

Second step select the first query again, the Operator (+), and the value (32).  
Give this another alias (This would be the final number).

To keep each number together, I had to apply a filter selecting the corresponding query, and make sure that Replace all Fields was selected. Then I could apply colors, thresholds and everything else.

The old panel I had to set the items to transparent and then just shrink it down so it was not the focus on my main screen. (There is no way to hide a panel you do not want to see).

---

<div class="post-metadata">

**Author:** ![nedra](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@nedra](https://community.grafana.com/u/nedra)\
**Post date:** [January 28, 2024, 2:58pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/13 "2024-01-28T14:58:29Z")

</div>

thank you [msulewski](https://community.grafana.com/u/msulewski) for your response

---

<div class="post-metadata">

**Author:** ![nedra](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@nedra](https://community.grafana.com/u/nedra)\
**Post date:** [January 28, 2024, 3:20pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/14 "2024-01-28T15:20:21Z")

</div>

What is your version grafana [msulewski](https://community.grafana.com/u/msulewski),I have latest version (10.3.1) but I didn’t have this option

 ![bugDashboard](https://us1.discourse-cdn.com/grafana/original/3X/1/9/19d9709b0f6646cbe91b0aa664e731bdcae470cc.jpeg)  
this my panel  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/3/5/358c3504206a830783ad4ec81de987779c6c66ca.png)  
thank you a lot

---

<div class="post-metadata">

**Author:** ![msulewski](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@msulewski](https://community.grafana.com/u/msulewski)\
**Post date:** [January 29, 2024, 2:13pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/15 "2024-01-29T14:13:50Z")

</div>

I am on Open Source version 10.2.3

---

<div class="post-metadata">

**Author:** ![isaqueprofeta](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/isaqueprofeta/32/38142_2.png) [@isaqueprofeta](https://community.grafana.com/u/isaqueprofeta)\
**Post date:** [February 1, 2024, 8:56pm UTC](https://community.grafana.com/t/query-breaks-when-host-variable-is-used/112762/16 "2024-02-01T20:56:10Z")

</div>

Any information if this has any relation between wide and single series data? For another similar reason I asked for a issue on [Transformations: Reduce with reduce fields don't work with wide-timeseries dataframes · Issue #71303 · grafana/grafana · GitHub](https://github.com/grafana/grafana/issues/71303) and I was answered with a WAI that I don’t agree… Maybe if it’s a similar reason, it could help.

I remember that there’s some data from zabbix that grafana transforms to Wide series, and some data that goes as Single Series… Causes some trouble when transforming data.
