Can I use a variable as a variable name in a query?

My dashboard has three variables. I’d like to use ‘level’ variable to choose which one to use in the prometheus query. The value of the level variable is determined by one of the three variable names.

If the three variables are named foo, bar, and baz, I can set the value of the level variable to either foo, bar, or baz.

I want a query that looks like this to work.


but it doesn’t work.

Can I use a variable as a variable name in a query?

To the best of my knowledge, this is not supported. Could you share a bit more about your use case?


I want to aggregate the metrics by level and repeat the panels by level.

For example, this dashboard (
repeats panels for each server variable. I want the user to choose whether to repeat the panel about the app or the server.

The question is a little old, but I had the same problem in some late 6.x Grafana and was surprised not to see it answered. So in case someone has a similar problem, I want to share my findings.

First of all, I want to mention that in my case I wanted to use a variable as part of a variable name in a query to an influxdb 1.7 datasource.

I had a dashboard variable named $stage defined as Custom list: PROD, QS
Then I had other variables, which had either PROD or QS in their names, e.g.
$PROD_hosts and $QS_hosts, which both had lists of host names

In the query I managed to refer either PROD_hosts or QS_hosts, dependent on the user’s selection in $stage:
... WHERE "host" =~ /^${${stage}_hosts:regex}$/
Note how the inner variable ${stage} is resolved first to build the final variable name.
I had to use the :regex modifier, since by default I got a json notation for the list of hosts.

Unfortunately, this construct cannot be used for repetitions, simply because you cannot edit the field for the repetition variable to enter the variable expression (only selectable from the dropdown list). :-/
Of course you can use the inner variable ($stage) as repetition variable, though.