Map all values from a query variables in a dashboard's panel

I am using Grafana 9.2.0 and I have a use case whereby I have a query variable called host_name that maps an host id with a specific user friendly name. The variable is fine and all good. The variables works on dashboard load with the below options:

I have a specific panel with the following query:

round(sum by(service_name) (rate(my_metric{service_name="aService", host_id=~"$host_name"}[2m])),1)

In the panel’s definition, I have also set this override value:

This is fine if I select a specific (just one) host_name from the top menu, but if I select multiple values, it just creates a legend value in the panel of this kind:

host_name1 + host_name2 + hostname3 Total 2345

I would like to have each host_name and its value shown separately. How can this be done in a dynamic way?

Thank you

What do you mean by this?

I mean that currently I can only show the following:

host_name1 + host_name2 + hostname3 Total 2345

with the calculation set to Total. It works fine when I have only one host_name, but I would like to have the total value for each of them, e.g.:

host_name1 Total 234, host_name2 Total 300 etc

Is this even something I can achieve?

1 Like

Maybe look on the BInary Operation Transformation? Not sure what your data source is. would be better to do it on that side of things.

1 Like

Sounds great, thanks. Never worked with it, but it looks like it should resolve my issue. Appreciated, thanks.

1 Like

I should have mentioned that my data source is Prometheus. Does your suggestion apply to that as well? Thanks

One way to find out is to try and fiddle around with it :wink:

Thanks, I will have a better look. I can see that I can only apply Time and whatever is my service_name value to Binary Operations. It also looks like that allows more than I am looking for. I just need to treat individually each of the value from my var. I will see what I come up with.

Hi, im not sure if you got your solution working but maybe i can help you or someone else in the future that stumble upon this.

When you select multiple values, Grafana will do a simple interpolation between the names (in this case, a “+”).

There is however a way to specify the format you want them to appear:

if you write


It will convert the 2+ selections into a json-accepted format.

Grafana Template Variables Syntax