# Panel repeat based on chained variables

**URL:** <https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176>\
**Category:** Dashboards\
**Tags:** templating\
**Created:** [March 17, 2024, 1:03am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176 "2024-03-17T01:03:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alpglide](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@alpglide](https://community.grafana.com/u/alpglide)\
**Post date:** [March 17, 2024, 1:03am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176/1 "2024-03-17T01:03:02Z")

</div>

I have a dashboard. There are two variables both with all option:  
1:interface, for example, with three values: A, B, C.  
2.definition, which is queried from a postgresql database based on $interface. for example, A-\>1/1/1, B-\>1/2/1, C-\>1/3/1 ( each $interface has only one definition. both interface and definition columns are unique).  
I want panels to repeat based on $interface. in each panel, the title is $interface, but use $definition in the influxdb query, for example, select Rx from m1 where def=$definination.  
so  
#1 panel: title ='A"; query = select Rx from m1 where def=‘1/1/1’,  
#2 panel: title = 'B"; query = select Rx from m1 where def=‘1/2/1’,  
#3 panel: title = ‘C’; query = select Rx from m1 where def=‘1/3/1’ .

I read this [post](https://github.com/grafana/grafana/issues/63363):  
but, is there any work around to do this?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![alpglide](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@alpglide](https://community.grafana.com/u/alpglide)\
**Post date:** [March 17, 2024, 1:43am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176/2 "2024-03-17T01:43:47Z")

</div>

I understand the [post](https://github.com/grafana/grafana/issues/63363) said that “This is not supported, as variable query execution only happens at the top level for the whole dashboard.”  
but in my situation, the query only need execute at the top level for the whole dashboard.

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [March 17, 2024, 2:04am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176/3 "2024-03-17T02:04:10Z")

</div>

Generally, you don’t need to chain variable. Use key/value variable, because Postgresql, e. g. variable `interface`:

```auto
SELECT 
  title AS __text,
  def AS __value 
FROM interfacestable

```

Then repeat panel by that variable and use `${interface:text}` in panel title and `${interface:value}` in the query.

---

<div class="post-metadata">

**Author:** ![alpglide](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@alpglide](https://community.grafana.com/u/alpglide)\
**Post date:** [March 17, 2024, 2:18am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176/4 "2024-03-17T02:18:06Z")

</div>

Your solution does solve the problem. Your help is greatly appreciated!  
If there are more variables, and they are all one-to-one map. Just image now we also need ip with interface, definition.  
any suggestion to that?  
Thanks again in advance.

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [March 17, 2024, 8:08am UTC](https://community.grafana.com/t/panel-repeat-based-on-chained-variables/117176/5 "2024-03-17T08:08:14Z")

</div>

> [@alpglide](#):
>
> Just image now we also need ip with interface, definition.

It depends on the use case. I guess IP should be used in the the panel legend: so you already have “metric” query, add aditional query just to query other metadata (e. g. IP, MAC,…) and then use join transformation to join “metric” and “metadata” query results into one result by common column (e. g. def).
