How do you sort stacked bar chart by value

The stacked groups in a Vertical stacked bar chart can be sorted alphabetically. However, I want to sort them by value where the largest value shows up in the bottom. Is there any way to do this?

Hi @sambhavbhandari -

Currently QS will not sort the Group/Color using a value. Here is a workaround that you can use.

Step 1 - Create a calculated field that will show your stacked group plus what rank the value is.


rank([value DESC],[col2], PRE_AGG)

Step 2 - Concat your rank + your stacked group.



Step 3 - Change the legend colors so that all stacked groups are the same color.

Step 4 - Hide the legend and create your own legend with a custom visual (if desired)



Hi. How can you make this work when you want to sort not by a value but through an aggregated value (ex: sum({value}) DESC in your example). The problem I run into then is that I cannot create the c_sort_col1_string since it cannot mix aggregated and non-aggregated fields in the concat.

Thanks in advance for your help.

The possibility to sort by something else than the alphabetical order of the group would be more than welcome…

Hi @cedneve -

You can use a level aware aggregation in your calculate field.

concat(toString(sumOver(value, [], PRE_AGG)),'col1')