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

  • 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

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:

Thanks @mattabrams
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”)

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

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