How to get Grafana dashboard variables into flux query?


in influxdb 1.x I used a dashboard variable to repeat a row of a dashboard.
In influxdb 1.x during creation of the query I get a popup window to choose variables from.

Now in influxdb 2.0 and flux queries I don’t know how to access the dashboard variables to get repeated rows as well:


I tried also:

|> filter(fn: (r) => r["host"] == ${myvariable})

but got this error:

invalid: compilation failed: error at @8:37-8:38: invalid expression: invalid token for primary expression: ILLEGAL

Can someone please tell me how to get the variable into my flux query?

Thanks a lot…

I don’t know if it works the same way in Grafana, but in InfluxDB 2.0 it just does:

r["host"] == v.myvariable

Hi Franky,

I tried this as well, but it gives me:

invalid: error @8:37-8:38: undefined identifier v

if I just enter v. then I get a list of variables I can choose from like


But my dashboard variable is not within this list.

I think you should rather ask the question in the Grafana forum, because I think this is a Grafana problem, how the variables come from the dashboard into the flux queries and how they are called there?

Hi Frank,

yes - I did already.

Try it with:

r["host"] == "${myvariable}"


r["host"] == "myvariable"

Hi Franky,

the 1st one I tried already (I mentioned in my 1st post).
The 2nd one gives me:

invalid: error @8:37-8:49: undefined identifier myvariable

Meantime I found it by myself, instead of:

|> filter(fn: (r) => r["host"] == ${myvariable})

it shoud be:

|> filter(fn: (r) => r["host"] == "${myvariable}")

This is what Franky suggested but I forgot the quotes in my test.
So I just missed the quotes - hope that helps someone

1 Like

This above mentioned line is the solution (the quotes are important)

Hey @Franky1 and @T_Burns,

I have managed to replicate the call of Grafana variables as you stated.
Now i want to build it into a part of a text. What i want to do is a Query that looks like this:


from(bucket: “MyBucket”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> filter(fn: (r) =>

r._measurement == "MyMeasurement" and

r.Generic_Name == "Weight_Indicator_Machine_**{Variable}**" 


I couldn’t make it work. Do you have any ideas how this might work?