# Access to the value of a custom variable key:value from another custom variable value

**URL:** <https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039>\
**Category:** Dashboards\
**Tags:** dashboard-variables\
**Created:** [March 27, 2024, 4:38pm UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039 "2024-03-27T16:38:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucamir](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lucamir](https://community.grafana.com/u/lucamir)\
**Post date:** [March 27, 2024, 4:38pm UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/1 "2024-03-27T16:38:28Z")

</div>

Hi folks,

I have started building an interface using Grafana 10.4.1 and I’m looking everywhere to solve the problem in the topic, but I have not found any solution. I have read many posts about it and they all refer to using chained variables with query variable. I just want to use custom variables.

The result I want to achieve can be of two types:

The first one could be get the value of a custom variable setting the key from another one.

Ex:  
$variable1 contains (var1 : 0, var2 : 1)  
$variable2 contains (0 : 101, 1 : 200)

Result = $variable2[variable1]:value.

In alternative i can put more than one value inside a custom variable like for example

Ex:  
$variable1 contains (var1 : { 0, 101}, var2 : { 1, 200})

and access to this values in some ways.

How can i achieve one of these two solutions ?

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/38541_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [March 28, 2024, 6:28am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/2 "2024-03-28T06:28:28Z")

</div>

> [@Referencing Key/Value variable with another variable as the key](https://community.grafana.com/t/referencing-key-value-variable-with-another-variable-as-the-key/82362/2):
>
> You need only one variable. Use key/value pairs (follow syntax from the doc exactly e.g. key1 : value1,key2 : value2 - don’t add additional spaces) and then you can use ${var1:text} to access a key and ${var1:value} to access value.

---

<div class="post-metadata">

**Author:** ![lucamir](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lucamir](https://community.grafana.com/u/lucamir)\
**Post date:** [March 28, 2024, 7:33am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/3 "2024-03-28T07:33:15Z")

</div>

This solution does not entirely solve my problem, because I need to keep as a key an explanatory label to be displayed in the menu, while the other pair of data would correspond to an ID and a value to be associated with it.

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/38541_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [March 28, 2024, 8:12am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/4 "2024-03-28T08:12:07Z")

</div>

![image](https://us1.discourse-cdn.com/grafana/original/3X/e/9/e91d59e411223a81acda0d11259bd896e69f7095.png)

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/b/0/b01bfbb5feb6bb912eadb5818140107224776374.png)

---

<div class="post-metadata">

**Author:** ![lucamir](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lucamir](https://community.grafana.com/u/lucamir)\
**Post date:** [March 28, 2024, 8:47am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/5 "2024-03-28T08:47:18Z")

</div>

Am I wrong or this solution show both menus for variable 1 and variable 2?

I need to have something like this, a dropdown menu where i can select the element using the label and then i get the id and the relative value from another variable, but is not possible to associate 2 variables. I mean probably i need to use the chained variable but I could not find any examples using them with custom variables.

![Screenshot 2024-03-28 094137](https://us1.discourse-cdn.com/grafana/original/3X/1/9/19100bd834d073ceab6fe44bc260239cf15885cf.png)

 ![Screenshot 2024-03-28 093950](https://us1.discourse-cdn.com/grafana/original/3X/8/4/841a8c3fec1d567f0c0232fe77117c36c6524fcb.png)

I generally need to use the CARS\_PAIRS value and text but i need to select the cars from the CARS variable that rappresents the dropdown menu for the user.

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/38541_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [March 28, 2024, 12:09pm UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/6 "2024-03-28T12:09:25Z")

</div>

really ugly workaround:

1st variable: list of cars, and “models” in csv ( i used inline, but you can use a url, and get a dynamic list)

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/8/9/8913ff34fbefeb8f94d579e488c9506c5c27f42f.png)

2nd variable: json array of “models” and “prices”, then filtering by getting value from the 1st selected variable

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/a/9/a97d94ea3d0d6d97b62da1a3c3add0ab70134ab1.png)

result: one drop down showing cars to select, “price” returned from json array

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/2/a/2a4566e0039f2e48f308ee7b3dcfff7b478ceed7.png)

This is not very elegant, and can probably be simplified, but it works, and it took a surprisingly long time to do such a “simple” task…

---

<div class="post-metadata">

**Author:** ![ushi](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@ushi](https://community.grafana.com/u/ushi)\
**Post date:** [November 1, 2024, 8:42pm UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/7 "2024-11-01T20:42:19Z")

</div>

Hello, is it possible to replace the selected number with a string in the JSON input? Something like this does not work for me:  
{  
“016” : [“word”],  
“020” : [“sentence”]  
}

Thanks

---

<div class="post-metadata">

**Author:** ![ushi](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@ushi](https://community.grafana.com/u/ushi)\
**Post date:** [November 7, 2024, 10:42am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/8 "2024-11-07T10:42:10Z")

</div>

For some reason only the following example [Simple Queries · JSONata](https://docs.jsonata.org/simple) allows me to replace the number with a string:  
[  
{ “ref”: [“top”,2] },  
{ “ref”: [“middle”,4] },  
{ “ref”: [“bottom”,5] }  
]

---

<div class="post-metadata">

**Author:** ![grosserg](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grosserg/32/54650_2.png) [@grosserg](https://community.grafana.com/u/grosserg)\
**Post date:** [May 16, 2025, 8:30am UTC](https://community.grafana.com/t/access-to-the-value-of-a-custom-variable-key-value-from-another-custom-variable-value/118039/9 "2025-05-16T08:30:38Z")

</div>

This doesn’t work for Grafana v7.5
