Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
sash
Frequent Visitor

Stacked column chart: Sort legend by value, not alphabet

Hi,

 

Is there any way of configuring the stacked column chart to sort the stacked groups by value and not by alphabet? 

 

I've found a similar question and a solution here (using the group names and prefixing them; like 1_name, 2_name, etc.): https://community.powerbi.com/t5/Desktop/Modify-the-legend-order/td-p/25337. However, in my case I don't want to define the order myself, I want it to be dynamically sorted based on the value of the measure (highest value on the top). 

 

Here is an example of what I want to achieve:

 

example_stackedcolumnchart.png

 

 

 

1 ACCEPTED SOLUTION
v-sihou-msft
Microsoft Employee
Microsoft Employee

@sash

 

If you have only one category on X-axis, you can have your Legend column sort by Value column.

 

Capture.PNG

 

If you have multiple catgories on X-axis, this method will not work. You have to manually define the order column in your table. 

 

66.PNG

Regards,

View solution in original post

5 REPLIES 5
fcasalen
New Member

I have a solution for multiple x categories. The thing is that it doesn't change the order for each x, but sort all x by value in the same order, which, for me, is more informative.

for example, when I created a stacked chart with my data, I got this:

fcasalen_0-1670614810926.png

Which I think it's not very easily readable. I wanted the first bar to be the one with highest value and the next one in order linke the one chart below (the same data):

fcasalen_1-1670614917315.png

To do this, you only need to create a table with summarize, where you will summarize the table where the data is by the legend column and the value column.

New_Table = SUMMARIZE(Table,Legend_Column,Value_Column)
It will depend on your data, but for this to work, every legend needs to have on distinct value, so the new table will have 2 columns e x lines, where x is the number of distinct legends.

Then you create a relationship between the legend_column in the new table with the legend_column in the the original data table.

Then you sort the legend_column in the new table by the value column in the new table.

Then you replace the legend in the stacked chart by the legend column in the new table and you decide wether to classify the legend order ascending or descending on the top right corner (3 dots).



v-sihou-msft
Microsoft Employee
Microsoft Employee

@sash

 

If you have only one category on X-axis, you can have your Legend column sort by Value column.

 

Capture.PNG

 

If you have multiple catgories on X-axis, this method will not work. You have to manually define the order column in your table. 

 

66.PNG

Regards,

This is an old post, so I am wondering has this facility been deprecated?  Because I can't see how to do it, what am I missing?

 

Thanks

On multiple categories x-axis, while preserving the x-axis sort order, I would like to sort the stacked column by value, not alphabet. And doing this dynamically. Any pointer on what calculated column / measure / DAX to do this, rather than manually define the sort order for each x-axis category?

Anonymous
Not applicable

Welcome to the world of Power BI!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.