I landed here because I wanted to use variables in the "Filter data by value" transformation in Grafana.
Looks like it is still not supported as of today (see feature request), but depending on what you want to do exactly and which data source you use, you might be able to achieve the same in the query (which didn't work for the Andi, who posted the question, as far as I understood - but maybe it helps someone else):
E.g., I use InfluxDB and had this query:

I wanted to display only "z_amp" values where the "freq" field matches the $freq variable.
I converted the query into text and added 'AND "freq"=${freq}' to the end:
SELECT "z_amp", "freq" FROM "xyz_data" WHERE ("slave_id" =~ /^$slave_id$/ AND "slave_xyz" =~ /^$xyz_id$/ AND "op_cond" =~ /^$op_cond$/ AND "xyz_valid" =~ /^$is_valid$/) AND $timeFilter AND "freq"=${freq}
Using a "Filter by name" transformation, I can hide the freq field again, so only the matching z_amp values are shown.