# Repeating panel: how to use a variable as the key to another variable?

**URL:** <https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667>\
**Category:** Grafana\
**Tags:** templating\
**Created:** [August 31, 2021, 3:59pm UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667 "2021-08-31T15:59:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipefischmann](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@felipefischmann](https://community.grafana.com/u/felipefischmann)\
**Post date:** [August 31, 2021, 3:59pm UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667/1 "2021-08-31T15:59:22Z")

</div>

- What Grafana version and what operating system are you using?  
v8.0.3 Windows

- **What** are you trying to achieve?  
I have 2 variables.  
Variable1: FOO,BAR,BAS,  
Variable2: A MSSQL query that returns a key-value pair such as FOO\_ETC:12, BAR\_ETC:12  
I have a panel that repeats for each value in Variable1, which is used in most queries.  
I would like to **add a query using the respective value of Variable2** : so for example in the FOO panel instance, use the value 12.  
I know that if the panels were repeating on Variable2 instead of 1, I could get that value easily with {Variable2:value}. However, I have to use Variable1 (because in some cases Variable2 doesn’t have an entry but I still want to show the other queries).  
I’d think it would be possible to somehow, for each panel instance:

1. Create the corresponding Variable2 string, based on the value of Variable1 - this is possible with “${Variable1}\_ETC” → “FOO\_ETC”
2. **Use the string above to access the corresponding value of Variable2**. Really just like using a key in a dictionary. In Python terms for example, as Variable2[“FOO\_ETC”]. But I’m not aware of this being possible in key-value variables in Grafana.

- **How** are you trying to achieve it?  
I’ve read a lot of questions and documentation but couldn’t come up with anything to get started.

- What happened?  
N/A

- What did you **expect** to happen?  
N/A

- Can you copy/paste the configuration(s) that you are having problems with?  
See above

- Did you receive any errors in the Grafana UI or in related logs? If so, please tell us **exactly** what they were.  
Didn’t get to this point

- Did you follow any online instructions? If so, what is the URL?  
N/A

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [October 21, 2021, 8:20pm UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667/2 "2021-10-21T20:20:11Z")

</div>

Generally speaking, @felipefischmann, you will want to explore chained variables. Check out this doc and the linked examples. The example dashboard are a great starting point for building your own template:

> **[Chained variables](https://grafana.com/docs/grafana/latest/variables/variable-types/chained-variables/)**
>
> Chained variables Chained variables, also called linked variables or nested variables, are query variables with one or more other variables in their …

---

<div class="post-metadata">

**Author:** ![felipefischmann](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@felipefischmann](https://community.grafana.com/u/felipefischmann)\
**Post date:** [October 22, 2021, 8:40am UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667/3 "2021-10-22T08:40:21Z")

</div>

Thanks @anon70503803  
I did have a look into chained variables but it doesn’t seem to be exactly what I need.  
My understanding is that with chained variables the idea is to use values from one variable to filter values from another variable, on the dashboard level.  
What I need to achieve is, within a query, access a single value of a variable (12) by using as a key a string (“FOO\_ETC”) that is built using another variable value (“FOO”)

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [October 22, 2021, 5:46pm UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667/4 "2021-10-22T17:46:39Z")

</div>

hmmm, you can create key:value pairs using `custom` type variables. Maybe there is a sequence here but I’m not sure…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [August 31, 2022, 3:59pm UTC](https://community.grafana.com/t/repeating-panel-how-to-use-a-variable-as-the-key-to-another-variable/52667/5 "2022-08-31T15:59:44Z")

</div>

This topic was automatically closed after 365 days. New replies are no longer allowed.
