Custom variable: now add in 1 key few values

Hi!
Grafana v10.4.1

I would like a list of data to be passed as a custom variable to the query when selecting a specific key.

I have the following information:

Sam is in the green group
Nickname in the green group
Victoria is in the green group

Jerry is in the purple group
Chris is in the purple group

In this case, “purple group” and “green group” are the keys, аnd people are the value

I want “green group” to be passed to the variable when selecting “Sam, Nickname, Victoria”

For example

SQL query
" select * FROM mytable
where employee_username in ($group)"

in such a drop-down menu there are such groups
Снимок экрана 2024-04-04 в 21.57.23

And the request would be like this for execution
"
select * FROM mytable
where employee_username in (‘Sam’, ‘Nickname’, ‘Victoria’)
"

This doesn’t work:

1.) You have preview, where you already see that you don’t have desired result - you have indication, that your definition is wrong:


2.) There is example how to define it, so just follow that example

3.) So correct syntax can be:

4.) just use it in the query:

select * FROM mytable
where employee_username in (${group:raw})

Of course verify it and fix any issues to have valid sql for your use case.

1 Like