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

1 Like

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 ?

Bumping this for visibility, as I too would like an answer. Running into the same issues.

You can reassign the variables with their current values that you want to keep like:

/d/${__dashboard.uid}/${__dashboard}/?var-variabletochange=${__value.raw}&var-variabletokeep=$variabletokeep

Re-testing with Grafana v9.5.1 (bc353e4b2d)

Solution proposed by @sbence is not working for me. The part &var-variabletokeep=$variabletokeep is pushing the list of values between curly bracket to the filter. It’s not recognized, the queries will return no data. Clicking on the filter will revert to All.
Perhaps it’s linked to my datasource ? (Using Altinity plugin for ClickHouse by Vertamedia version 2.5.3)

But the previous solution more or less work now with the last version of Grafana ( v9.5.1 ). There is still a glitch but minor.

Here is the data link used on the pie chart :

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

The display is srange (All + xx) but the filter xx is properly applied anyway in the queries, and clicking on the filter show it clean.

image

To Sumarize.

a) At least two Variables, in my sample here Severity and Category
b) in the dashboard two pie charts, on for each, with filters matching the variables

$conditionalTest(AND Category in ($Category),$Category)
$conditionalTest(AND Severity in ($Severity),$Severity)

c) for each pie chart, a data link set with matching variable :

pie chart Severity

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

pie chart Category

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

d) clicking on one of the pie chart will apply the corresponding filter
e) remain the issue with the All + displayed but the data part works…

Note, for a bar chart the data link is different. To be figured out for different type of chart.

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

Stephane.

PS : you can also add a dashbaord link to add a button to clear all filters, keeping or not the date changes by checking/unchecking the Include current time range.

/d/${__dashboard.uid}/${__dashboard}