Templating and variables - how to assign one variable value based on choice of another variable

Hi

I have a problem with templates in Grafana that I am not sure how to solve.
Lets say I have a variable $Customer - list that have one of values e.g. “Hewlett-Packard”, then I need another variable e.g. $Tablespace to be populated by value “HP” automatically.
So the way I am trying to do this is to define some table that would automatically populate the variable values based on chosen $Customer.
Like a csv
$Customer;$Tablespace
Hewlett-Packard;HP
Customer2;Tablespace2
Customer3;Tablespace3

Is there any way to do this?

br
David

Do you mean being able to chain/nest template variables?

You do not say which data source you are using. Here are some examples:

Thanks for the reply - we use graphite as a backend

There isn’t anywhere in Grafana to provide a mapping (from Hewlett-Packard to HP). You could possibly to do it with Regex if it is always the first character.

If the Regex solution would work then combining chained template variables with Regex capture groups might work:

Otherwise, is it possible to get that mapping from some other data source (mysql maybe)?

Thanks for reply, that is not actually possible - this was just an example in reality the abbreviation is not always first characters, I think the easiest way to do this in my case is to create specific dashboard for each customer… I just was making sure to check the possibility of doing this template way, so I learn a thing or two :slight_smile:

Hello Dan,

this is something what i would like to solve too - i have ID (number), which i need to get correct data from different tables (across Influx and MySQL DB), and then i have some labels for those IDs (in MySQL), which i would like use in variable menu with those IDs. So instead of:
21
23
24
to have
21 - Corner office
23 - Cafeteria
24 - Meeting room

Is there a way how to this? Because when you asked if it’s possible to get mapping from MySQL, maybe it is.

Thanks

From the docs for MySQL:

Another option is a query that can create a key/value variable. The query should return two columns that are
named __text and __value. The __text column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with hostname as the text and id as the value:

```sql
SELECT hostname AS __text, id AS __value FROM my_host
```

@daniellee

To create the variable I am using this query
Var 1. SHOW TAG VALUES FROM Mydata WITH KEY = InstanceIP

Var 2. SHOW TAG VALUES FROM Mydata WITH KEY = RegionName

Now my question is , Is it possible to use Var 2 in the query of Var1.
Something like
SHOW TAG VALUES FROM Mydata WITH KEY = InstanceIP WHERE RegionName=Var2

Thanks

I use Prometheus as the backend.
And I want set two variables in grafana templating: cluster and instance. Each cluster have one instance. Just like:
cluster1 —> instance1
cluster2 —> instance2
cluster3 —> instance3
But when I select cluster1, instance show None, I dont know why, anyone here can help me?
Here are some infos:
templating
templating_prometheus

More infos here:
request

request here:
Request URL: http://10.111.24.95:9050/api/v1/series?match[]=node_boot_time{cluster%3D~"cluster1"}&start=1544233581&end=1544233881
Request Method: GET
Status Code: 200 OK
Remote Address: 10.111.24.95:9050
Referrer Policy: no-referrer-when-downgrade

result2

The Prometheus example not available…