How to select a variable index

Hi all,

Really sorry but was hoping someone could explain to me how I am able to select from a list of multiple variables in a query so that I only return a single variable in position 1,2,3 or 4 from the example below:

variable_name contains the following values
AAA
BBB
CCC
DDD

I tried indexing it using the following format but this doesnt seem to work.

WHERE MY_VALUE = {variable_name:1} OR
WHERE MY_VALUE = {variable_name:3}

I have looked at the documentation and here on the community forums but I am either going blind or it is just something that isnt supported?

Any help would be greatly appreciated. Loving Grafana so far!

3 Likes

Wondering if there were any updates that allowed this behavior. I’m using a plugin where I make multiple requests to a JSON API and would like to save some object ids in a variable. When writing the path to requests in queries, I would like to use this variable like this:

A:
/path/to/api/object/${object:0}

B:
/path/to/api/object/${object:1}

Instead of : you can use . ${object.0}

3 Likes

As a follow up, is it possible to get just the text of this? I’ve tried both ${variable.0:text} and ${variable:text.0} and neither seem to work, though they do give different results

No matter what I try I can’t seem to get it to split it into the individual pieces of text.

“Your approach is effective. However, please ensure that the ‘ALL’ option is selected when creating the variables. Failure to do so may result in indexing characters instead of the entire string. For instance, in the scenario provided where values are ‘AAA’, ‘BBB’, ‘CCC’, ‘DDD’, omitting the ‘ALL’ option would lead to ${myvariable.0} returning ‘A’ instead of ‘AAA’, and ${myvariable.1} returning ‘B’ instead of ‘BBB’. By selecting ‘ALL’ and subsequently using ${myvariable.3}, you will obtain ‘CCC’ as expected.”