Using a variable in value mapping ranges

Using Grafana v10.4.0

I’m trying to make a bar chart where the bars below the average value are colored red and the ones above the average value are colored green. The average value is a variable that will be periodically recalculated. I tried to achieve this by using value mappings and using a range, but it won’t allow me to use a variable as a range value. Is there another way of doing this?



For example, I would like to use the average value instead of the hardcoded value of 500 I have set now for testing purposes.

chrome-capture-2024-7-29

select *, 
 case when guz < ${threshhold} then 'low'
 else 'high' end as bonbon
 from (
  select 22 weekNumber, 0 guz union
  select 23 weekNumber, 1968 value union
  select 24 weekNumber, 1132 value union
  select 25 weekNumber, 232 value union
  select 26 weekNumber, 0 value
) a 

then create a value mapping override using high low then use color setting based on bonbon to choose colors that match override colors.

for the line you can use Business Chart