Get value from key/value by key.name

Hi all. I know that i can set key/value (map) and later reference key or value by ${var:text} or ${var:value}. The question is: is it possible to reference a map value by key name in another variable? Assume I have a variable VAR1 of type custom set as map var1:val1 , var2:val2. And I have another variable VAR2 of type Query whiche gets tag values: tag_val0, tag_val1 etc. So I want to set variable VAR3 to the value of VAR1 depending on the value of VAR2 so that the value of VAR3 is set as the value of VAR1 key, where VAR1 key equals to VAR2, i.e. VAR3=VAR1[VAR2].

I tried to set VAR3 as ${VAR1.$VAR2:value} but it doesn’t work as expected.

see this thread:

@sowdenraymond
Thanks for your response, but this doesn’t work for me. Any ideas why?



image

${var1:value} : ${var2:text}

@yosiasz thanx for reply
Actually I’ve tried this either (sorry for not mentioning) without success:


check out the example here:

https://play.grafana.org/d/aecv3off9p98gc/143543

1 Like

works on my pc :laughing:

1 Like

Follow the steps
Step 1:


Step 2

Step 3

Final output

Hi, sorry for delayed reply. I see that it works as expected on cloud version of grafana, but on my on-premise free self-managed version I still can’t get it to work. Does it mean that it actually shouldn’t because this only is supported on cloud version? Any ideas?

@yosiasz what version of Grafana are you using?

@infofcc3 thanks for sharing. I’d prefer to use native mechanisms if possible, otherwise I will be forced to implement workaround solution like yours. Do you face the same issues?

i always use latest.

1 Like

Yes, I’m facing the same issue. Grafana doesn’t seem to have a built-in method to reference a map value by key. So far, I’ve had to use a workaround. Let me know if you find a native solution.
Also you can follow Regex filtering option
Step 1: Define Variables (Custom variable as key-value list)
v1=1, v2=2, v3=3
Step 2: In VAR3 Apply Regex Filter
${VAR1:regex/.${VAR2}=(.),.*/\1/}
Note:“If your data matches exactly, then you can try it.”