Use custom variable in regex of transformation 'Filter data by values'

  • What Grafana version and what operating system are you using?
    Grafana 11.1.4

  • What are you trying to achieve?
    Use custom variable in regex of transformation ‘Filter data by values’ to filter single values and also show all values.

  • How are you trying to achieve it?

  • What happened?
    I get ‘No data’

  • What did you expect to happen?
    Return data based on regex

The variable $MyColors has custom values like this:

  • .*
  • red
  • green
  • blue

I entered the value .* in ‘Custom all value’. This is to show records with any color as ‘All’ option.

But for some reason I always get ‘No data’ no matter which color I select.

If I enter .* manually inside the transformations value field, the data is there as expected.
It works also if I enter one of the colors inside the transformations value field.

It seems that the custom variable is not considered or evaluated by the regex?

What I am missing please?

Please note:
I know that I can use custom variables in the database query, but I want to achive a client side filtering to avoid multiple queries against the database if user changes the color value.
transformationsVariableSupport is already enabled (by Grafana default)

@mrburns

Try → ${MyColors:regex} instead of $MyColors

@orosolido: Thanks, but this does not change anything :frowning_face:

@mrburns

hmm :confused:

Just as a test… try to see if the variable works. For .e.g.
put it in the title options and chance values.

ps. what Datasource are you using?

@orosolido: good idea,

Here the results for the title:

.* instead of All
red instead of red
green instead of green
blue instead of blue

I use mysql database, but this should not make any difference what database I use.

@mrburns

Agree, it shouldn’t matter
I was more aiming for the idea to integrate it into your query instead of using the transform feature.


It looks like it works. The question which now is .do $variables also work in combination with TRANSFORM.?

Let me check

I know that I can use variables in query. But this is what I wanted to avoid as I posted in my 1st message under the ‘Please note’ section.
I don’t want to run another query against the database server. I want to get client side filtering to speed up and reduce load on database server.

1 Like

@orosolido: Thanks for your help, but:

I now downloaded Grafana 11.2.0. and there it works :grinning:

I also can use just:

$MyColors

Inside the Value of the regex field:

@mrburns sure np!

Good to hear. I was about to msg you that for it didn’t work :sweat_smile:
So this is an issue in older versions

Yes - thanks!