Use the dashboard variables among the queries

Hi Team,

New to Grafana, I’m trying to filter the correct data set with the help of dashboard variables. To accomplish I shared the variables among the other dashboard queries.

Problem 01 :
The dependent queries do not load data.

When I hard coded it works

i think your first query result is not loaded when second query is launched,
maybeyou have to get first query on dashboard load and second on time range change
This is a working example with flux query :
first var

second var

I’m using an influxql, the DB I’m using was InfluxDB 1.8. I change the option as mentioned “On time range Change”, but the data not loading also getting some errors.


The real pain point is if I hard code the value on the query it gives the results, but when I initiate through the variable it didn’t show results.

Hi @gerardlj,

So based on your initial screenshots it is like this;

WHERE Envi='QA' (works fine)

But not when

WHERE Envi=$envo (fails)

Have you defined this variable ($envo) as an Alias in your query which you are using in the Dashboard?

Maybe add some bracket around your var like i did on my screen, i’ think you will need son quote too like “${var}”
i know you have not the same datasource but i think it’s irrelevant for this issue.

Try to use your second query in a new panel or in explore tab to be able to analyse the query sent to your base through query inspector.
like this :

Tried but no luck. Please find the snippets.
The envo variable

the ttype variable

What is your datasource?

The datasource was InfluxDB 1.8

Then what happens if you select the current datasoruce from Grafana to InfluxDB ?

Does it work then?

Datasource is not a problem. If you see the above screenshot. If I hard code its works, but if I assign a variable it’s not working.

Thanks, I just wanted to see if that helps.

I found this in our Documentation on how to use variables in Grafana for InfluxDB:

It describes the possible syntax along with examples.

I hope it helps you to resolve the issue.

1 Like