How to build a data link to filter current dashboard when there is more than one variable?

  • What Grafana version and what operating system are you using?

Grafana v8.3.4 (a551d74b11)

  • What are you trying to achieve?

Use data link in a pie chart to filter a dashboard on one variable when there is multiple variables.

  • How are you trying to achieve it?

So far I tried in a pie chart with two the data link there after.
The syntax is OK it’s the effect that is not doing what i’m expecting.

a)
/d/${__dashboard.uid}/${__dashboard}?var-TransactionType=${__series.name}

For this one the data link apply the filter on TransactionType but clear all the other filters variables, even clear the All, so the dashboard is in error

b)
/d/${__dashboard.uid}/${__dashboard}?${__all_variables}&var-TransactionType=${__series.name}

this one apply all filters first then add the TransactionType filter but, it keep the previous All value, so the filter become All + the value, that don’t work, the dashboard is in error too.

==> Is there a way to keep all the existing variable filter unchanged and replace the value for one variable filter ?

@steffanou, I think I’m following, but a screenshot might really help to show the community what you’re looking for. I’m curious how many variables you have.

It sounds a lot like the issues described https://github.com/grafana/grafana/issues/21459.

Have you checked out ${myvar:queryparams}? There are some examples of the expected behavior for it here

Hi @melori.arellano ,

I’ve upgraded the version to v8.4.1 and now it works with the datalink describe in a) except that If I use it for different charts and variables, they replace each other and don’t combine.

One pie chart TransactionType with the data link with TransactionType will apply the filter properly.
Another pie chart GroupType with the data link with GroupType will cancel the previous filter and apply the GroupType.
That’s because it’s rebuilding a link with the saved dashboard where no filter is aplied. Each time the data link is called it’s not adding to the existing filters but restarting from the saved version.

here is the dashbaord screenshot.

if I use this data link

/d/${__dashboard.uid}/${__dashboard}?var-TransactionType=${__series.name}

image

The filter is applied properly.

I can not use the syntax ${name:queryparam} as I can’t find documents or sample of how it work.

@steffanou are you able to share the dashboard json for the dashboard? I’m curious where you’re creating the links.

Hi @melori.arellano ,

I can’t share the json as there is information I’d rather not publish.

But here is the step by step screen shot story of setting up the links.

For each charts I would like to be able to click to change the filters. But like I said, click on chart 1 to apply filter 1, click on chart two to apply filter 2 on top of the filter 1… on so on, to drill down the data from the charts.

a) Sample variable / filter definition :

b) a chart, with in the panel option a data link

Note 1 : that in the WHERE clause of the SQL for each chart there is one line for each variable like:

$conditionalTest(AND TransTypeCode in ($TransactionType),$TransactionType)

Note 2 : for Pie chart I use the link

${__series.name}

/d/${__dashboard.uid}/${__dashboard}?var-TransactionType=${__series.name}

for bar chart

${__data.fields[0]}

/d/${__dashboard.uid}/${__dashboard}?var-TransactionType=${__data.fields[0]}

I still need to figure out the syntax that will work for each type of chart.

:question: So my question is still how to be able to make clicking on one chart data link doesn’t reset the others filters ?

:arrow_forward: For exemple is there a way to capture the current URL with existing filters instead of using d/${__dashboard.uid}/${__dashboard}? ?

@steffanou, thank you for providing all of the screenshots they are helpful to understand more.

I’d like to know more about the possible transaction types and your workflow. The dashboard variables in the drop-down apply to all of the panels in the dashboard.

So, if you want your Pie Chart and your Bar Chart to refer to different transaction types, you might want more variables. If you can share more about the relationships you’re trying to show, that might help the community to suggest a potential solution.

Some ideas I’m thinking of:

  • multiple variables
  • chained variables
  • using one panel as the datasource for the other one

Hi @melori.arellano ,

Thanks but my question is not related to thoses 3 points.

For one dashbaord that have multiple variables as filters and pannel that are using the fields linked to thoses variables in the chart, how can we have a datalink that add the filter on top of the already applied filters.

Ex : One pie chart TransactionType with the data link with TransactionType will apply the filter properly on the variable TransactionType.
Another pie chart GroupType with the data link with GroupType will apply the filter properly on the variable GroupType. BUT it will cancel any the previous filter applied.
That’s because a datalink as i’ve described above is recalling a link with the saved dashboard where no filter is aplied. Each time the data link is called it’s not adding to the existing filters but restarting from the saved version.

How can we make it so the datalink apply the filter on top of the existing filter appled ?