Change colors of values that are above average

I need to display data in Table panel, highlighting values that are greater than average of current query result.
For example, if my query returns values ‘16.25, 7.96, 9.12, 9.03, 8.76, 8.85, 9.21’, I need to change color of 16.25.

If dynamic thresholds (i.e. specify variable in Thresholds section) were supported, that could be done easily, but that’s not possible as of now.

So I perform the following steps:

I calculate average value using the following variable MyVar:

from(bucket: "MyBucket")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r["_field"] == "MyField")
|> group(columns: ["_measurement", "_field"])
|> last()
|> group()
|> mean()

To my query I add an extra column to be used for configuration later:

|> map(fn: (r) => ({ r with Avg: ${MyVar} }))

I am using ‘Config from query’ transformation to specify Threshold1:

Config from query

This is a result I receive:
Result

The only problem now is that I can’t change these colors (i.e. red and green).

Any ideas how to change these colors? Or how to solve main task (highlight values that are above average) in the other way?

I also tried to specify ‘Color’ instead of ‘Threshold1’ from 'Config from query, but didn’t succeed with it.

I am using Grafana 10.2.6

is this average the average over all the rows returned?
avg(15.42, 7.46, 9.11, 9.03, 9.19, 9.25, 9.44)?

Yes, that’s correct. I need to calculate average over all the rows returned (now I do it using variable, so no problem here), and then change color for all rows that have value which is above this average (so far I have solved it using ‘config from query result’ transformation, but can’t change colours from default green-red).

are you using table visualization?

Yes, Table visualization is used

to keep it simple I would go with dynamic text plugin. you can dynamically change colors that way. I am unable to do it using the regular table plugin

1 Like

Thank you, will look closer to that plugin. Would be helpful if there are any examples of presenting data in tabular form with colours defined by query using Dynamic text plugin (i.e. public dashboards).

1 Like

using this

1 Like