How to use multi-value custom variable in query alias?

Hi all,

I am trying to add multiple measurements from InfluxDB with one query using custom variables. For my custom variable, I use this setup:


I add the variable to the query in the following way:
image

This works as expected and it adds a entry to the graph for each selected value of the custom variable.

My problem is that the names of the entries in the graph aren’t very readable, these for example result in: base_devices.mean {name: 0_Meter}
I would like to change it such that the entries are named according to the keys set in the custom variable (eg Basecase and Basecase Heat), but I can’t figure out how to achieve this.

I tried setting the Alias field to ${variable:text} but this just results in “Basecase + Basecase Heat”. Is there a way to make the query select the matching value from the custom variable?

Thanks in advance! If you need any additional information, please let me know. I am using Grafana v8.5.13.

Welcome @finn to the Grafana forum.

Have you considered using overrides to simplify the display names, like this?

Thank you for the quick response. I have looked into that and it works fine. However I am looking for a way to automate the naming of the display names. Using the override, we still have to change the naming for each variable entry manually.

Maybe a “Rename field by regex” override?

Yes, I manage to extract for example base_devices with the regex rename. Is it possible to use this value to get the corresponding key? Or if I switch the values and keys in the variable around, use “base_devices” as the key to get the corresponding value from variable?

Is this possible in Grafana?

To elaborate a bit more on this. I would like the display names to have to correct value automatically.

So either that I can insert the variable name (with some additional formatting if necessary) in the Alias field. Such that when the query generates multiple graphs from the multi-valued variable values, the corresponding text of the variable is used as the display name.

Or by renaming the display names using the text from variable. And then somehow get the correct text from a given value (which might be extracted from the display names using regex). So for the example, you could use “base_devices” to get “Basecase”.

Is this possible to do within Grafana?