Pass value from one panel to another panel query

Hello,

I have a panel with results - displayed below

Now, how can I pass the value when clicked to another panel’s where clause?

Like if I click on any “State” in the above panel, e.g., “Alabama” - I need to pass that value to another panel’s where condition - is it possible?

I have seen the data link, which creates a url - thats not what I am looking for…I need the clicked value to be captured and passed as a variable to another panels query…

Appreciate your help - Thx

I don’t believe this is doable. Variables are the best approximation. Or links, but you said already this is no good for your use case.

Why not using link to itself and setting a variable along the way, then applying the variable on that “detail” panel? True, refresh will be triggered, but putting that aside, effect will be as you wanted it.

Sounds good -

Like in my image…I get the link - 192.168.100.190/Alabama - and it takes me to a ‘Page not found’ error…

Looks like I am not able to follow your instructions…

Pl. let me know if you can provide an e.g.,

Thank you very much - N

Define a custom variable like country. You’ll need to specify some value. Not important what you put there. Hide it (Hide=Variable):


On your table panel, go to the column style options for a particular field and select Render As Link. This will open a set of Link options. Now go to the address bar of your browser, copy the whole link and paste it into Url field of the Link Options:

Now delete everything to the right of ? and replace it with ?orgID=1&var_country=$__cell&from=$__from&to=$__to.
Save and reload. If you now click on the link, you’ll come to the same place, but if you look at the address bar, you’ll have var_country set to the chosen country, which means that $country variable is now set to your chosen country.
Now go to the second panel and edit your query to something like metric{country_label=~"$country"}.
Let me know if this works for you.

Thank you very much for your quick response…

Being a newbie - struggling a little bit to find out - where I can find the Col. Style option, may take some time - but I will…here is my screen shot on the table setup

image

I see column width etc., but not the screen you posted - again, I will do my homework and findout.

Now, here is what I am trying to achieve…
image

I have two panels - one which ‘As of Date’ by State and the right one is by county.

What I need is - on the left panel, when I select a ‘State’ like Alabama, I need to pass that clicked value as State to the right panel to bring all the Deaths in those Counties in that State.

I am pretty sure - the info you provided may solve this problem, but I need to first figure out - where I see the column style option and choose the Render value as link option.

Once again - Thank you very much - N

BTE - I did create a state_name variable - hidden.

This is the whole ‘States’ panel edit screen - couldn’t find the Column Style option & Render value as link also…Am I doing something wrong here? Thank you - N

You’re using newer version of Grafana, but no worries. You should be able to find those fields on the right side if you click Overrides.
Could you also show me the query of the right panel. I was assuming Prometheus as data source, but looks like you have something else. No worries, you’ll just have to stick your country variable to some specific place.

Hello sskrlj:

So here are the screen shots one by one explaining…

As mentioned earlier…I have 2 panels - left & right. Left has the states in the united states and the right has the counties for that state.

image

  1. Query for the right window

image

image

  1. Next - the override options - I couldn’t find Column Style, but here are the screen shots…

image

image

image

image

image

image

  1. My Data Source is InfluxDB

Pl. let me know if there is anything I can provide…

Thank you - N

Hello sskrlj:

I went and put the code in the Data Link option in the Override section for the column state.

Now my url shows…

But the cell value is not rendered…

Dont know where I can find the option to render the value, would appreciate the help!

Thank You - N

Hi nageshyr, When you use a variable from query parameters, the correct syntaxis is var-{{variable name}} with a dash instead of the underscore.

Hey Danielgonzalez,

Thank you for your reply…

I was able to sove the capture value problem thru this…

Now my problem is the second panel is not refreshing…so a brief explaination

I created a Hidden variable as suggested by sskrlj - glad he helped me to get to this point!

Then in Panel 1, I am getting the value
image

In the weblink, you see the value
image

Now in Second panel the Query the variable value is passed…
image

I am not getting the results, pl. let me know if I am doing something wrong…

Thx - N

Hi @nageshyr, I am back, so let’s push this through to the end. You sorted out Data Link brilliantly and it seem only the right side query is problematic. First, remove the trailing $after $state_nm. Then, I am not sure that you need regex expression in there, but I may be wrong. But you’ll probably need to add ' in front and at the back of the variable, like this '/^$state_nm/'. Or perhaps double quote, ", don’t know. I am not familiar with InfluxDB, but just try to tweak the query without the variable until it spits out what you want. What I am also seeing in the query is a leading space in front of Alabama, like /^ Alabama$/, which may also be causing difficulties.
Let me know how it goes and we’ll go from there.

Hey sskrlj,

Happy New Year!

I tried the option you mentioned and also looked into some InfluxDB forums, as per InfluxDB docs - the regex is simply
/$state_nm/ so I tried /$Alaska/ - /Alaska/ - and the others as you mentioned - ‘/^Alaska/’ - “/^Alaska/” - ‘/$Alaska/’ - “/$Alaska/”

Nothing worked - :thinking:

Thx - N

From example on https://grafana.com/docs/grafana/latest/datasources/influxdb/, try a simple State = Alaska. Would that work? Is regex really needed here?

Yes, if its actual text value like state = Alaska or Alabama - I get the results…

So, without the regex - I tried passing the variable -
state=$state_nm - didnt work

Good. I think the query is good, but the value of $state_nm isn’t as it’s prefixed with a space (looking at query from query inspector on one of the screenshots above). I think we need to look at the left panel query and see how those state values get populated and why is there a space prefix.

Left panel

Query

From Query Inspector

Query looks good. I suspect the problem in the ingested data. I recall that there’s a trim() function you can apply to the field. Do it for field us_state. This should get rid of that space.