Sort bar gauge by value of expression

I want to display a bar gauge to show the percentage of “X” records for each team.name, so I have a visualization with:

  • A (query): class: * Group by: Terms: team.name
  • B (query): class: X Group by: Terms: team.name
  • C (expression): $B / $A * 100

This shows up in my visualization as follows, not sorted:

I’m aware of the “Sort by” data transformation, but that doesn’t appear to solve my problem: expression C is not one of the fields it offers as options for sorting; instead, it offers the team.name labels which appear in query A and B.

How can I sort my bar gauge by the values of C?

I’m working from an elasticsearch data source, if that makes any difference. And I’m on Grafana v11.1.4.

Can you do the sorting on the datasource itself?

Thanks, yosiasz, but what would that mean? (The data source itself doesn’t have the calculation $B / $A, and that calculation is what I want to visualize and sort on.)

1 Like

oops sorry I see it now. is query A and query B on separate instance of ES or on same ES instance different index?

They are on the same instance and same index.

there is another plugin (Infinity) that you can use with ES that can do much more manipulation of data using jsonata

if you are interested in this approach that might simplify your solution please post sample es document you are working with.