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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Employee
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
Employee
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?

Welcome to the world of Power BI!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.