Sort by total X axis


I want to visualize using a stacked bar chart.
My need is to sort according to total X axis data. If you use sort by from count + group by, the results are like this. How can I achieve these needs?

I use metabase v0.44.2 and v1.47.1.

thanks before.

my expectation is the 11264 is second, and 9000 is third

1 Like

if you have a premium token, please write to help at metabase dot com

sorry, I don't have premium tokens. any other way?

Is it a Question or a Native query?

If it happens to be SQL, I can try to help troubleshoot.

this is happens in Question :frowning:

Okay, I think I have an idea for you. You can create a custom column in your Question:

Then use the custom column to sort:

Then turn off that column in the visualization:

Did suggested method solve the problem?

I have the same challenge: I'm collecting bicycle rides distance in 3 categories, and want a stacked bar chart graph, showing the total distance per person, and sorted by their total distance traveled.

How do I sort on total distance?
I cannot really use the proposed method, since my distance is just one single field.

Question construction:

Data in table format:

Stacked bar chart - clearly not sorted by total distance descending

I put a bit of time into this using some of my datasets. I can't figure out a way to do it without native SQL.

I managed to work it out after all.

Instead of summarizing by two categories (Name and Type), I created 3 custom fields to be able to SUM each of the distances I'd like to show in the graph:

With these 3 new columns, I can create the same graph by

  • summarizing on each of the 3 distances, plus the total distance, by Name
  • sorting on the total distance
  • and removing the total distance from the graph


Neatly sorted the proper way, without writing SQL or needing to fiddle in the mother database itself :slight_smile:

Good to hear! Thanks for sharing