Repeat query for each multi-pair variable with name labels

  • What Grafana version and what operating system are you using?
    Grafana 11.0
    Ubuntu 22.04 LTS

  • What are you trying to achieve?
    Repeat a time-series query for each value/label pair of a multi-value variable, and show a legend that has the label name of the variables.

  • How are you trying to achieve it?
    I have created a variable with a query to retrieve a list of IP addresses and a text label for each, I have used named capture groups to associate the two correctly. I then created a timeseries graph with the following settings:

SELECT “sensor” FROM “sensor” WHERE (“hostname” =~ /^$ipeltek$/ AND “sensor_descr” = ‘MainsVolt 1’) AND $timeFilter GROUP BY “hostname”::tag

  • What happened?
    The graph displays correctly, however the legend is only showing the value of the variable (in this case it is an IP address) instead of the text label (which should be a name)

  • What did you expect to happen?
    The legend to show the correct variable label instead of the values

  • Can you copy/paste the configuration(s) that you are having problems with?
    Here is my Variable config:

Here is my query and resulting graph:

Please note in the graph above, the legend shows a list of IP addresses, but instead, I want it to show the names of the variables (as shown in the variable definition screenshot)

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors
  • Did you follow any online instructions? If so, what is the URL?
    No guides followed as I could not find any that suited what I was trying to do but I asked for advice in the Facebook group

I used in my query CASE WHEN ip_address THEN name END as ip_adresses