Replace "+" symbol with replace in Grafana multi select custom variable

I have a custom variable defined with country name & country codes defined in following way:
Afghanistan : AF, Aland Islands : AX, Albania : AL, Algeria : DZ…

Variable has multi-value & include all options selected. I want users to select country name from the drop down and in the dashboard queries should be able to use both selected country name & country codes for various queries.

Everything works as long as only one country is selected from the drop down. If more than 1 selected, country name is returned as
Afghanistan + Aland Islands + Albania

Country codes returns as expected:
AF,AX,AL

Those plus symbols causing queries to fail. I attempted usage of regex but that didnt help

${Country:text} = returns names separated by Plus symbol
${Country:value} = returns comma separated country codes, no issues here
${Country:text.Replace(/\s++\s+/g, ‘,’)} = returns comma separated country codes for some reason :frowning:

How can I get both name & codes

  • What did you expect to happen?
    I want to be able to use both country name & codes.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    I attempted this with text panel. Using this in actual query returns “no data” as response.

  • Did you follow any online instructions? If so, what is the URL?
    multiple, dont have them handy now.

Use advance formatting, which fit your query needs:

Thanks, but which exact advance formatting you referring to?

I am using Key:Value structure in my variable and I used “:text” to get keys. The only issue - if multiple values are selected, it is returns+ delimited and cannot be used as-is as parameter.

ok, that’s not possible for :text (keys)

See relevant discussion and possible workarounds suggested in this topic:

will you use these vars on a database? mysql or ms sql?

using ${countries:csv} ${countries:json} ${countries:singlequote}

use 2 variables, one for country the other for country code.