cancel
Showing results for 
Search instead for 
Did you mean: 
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
Microsoft

@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
Microsoft

@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
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.