Search code examples
variablesgrafana

Grafana: how to filter queries within one panel?


I want to write 3 different queries within one panel. All the queries gonna return the similar structure of data: timeseries, several linegraphs in time.

I need Grafana to draw a visualization of just one of the queries depending on the option chosen in filter variable.

How can I do that?

The version is 8.4.3

I created a variable with custom names of options and tried to mention them within each query via $queryoption = 'Query A'.
Also tried to use 'Repeat options' on the right side in edit mode of panel. But no luck yet


Solution

  • You can do this by embedding variable in your queries, and returning results only if variable's value is corresponding to correct query.

    For example, create variable queryoption with values A, B and C.

    And add expressions into your queries that will be true only if according value of variable is selected.

    Query A
    select * from table1
    where 
     -- your existing where clause
     and '$queryoption' = 'A'
    
    Query A
    select * from table2
    where 
     -- your existing where clause
     and '$queryoption' = 'B'