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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Rank stacked column chart

Hi, 

 

Currently , I have stacked column chart below. 

1.jpg

 

The order of legend is defaultly as A-Z. 

 

How to rank the legends based on the YTD for every legend? 

 

Thanks for any help 🙂

1 ACCEPTED SOLUTION

You could use RANKX to create a calculated column that ranks each category. You just have to make sure that each category only has 1 rank, so every year for that category and every month it must be the same number ranking. 



Then you can use Sort By Columns to sort the category by rank and the legend will automatically update.

https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column


You may also be interested in Ribbon chart, which shows relative rank for each category and how it has changed from month to month: https://docs.microsoft.com/en-us/power-bi/visuals/desktop-ribbon-charts 

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

6 REPLIES 6
AllisonKennedy
Community Champion
Community Champion

You can change the order of the bars to sort by YTD value, but not the legend values. You can use Sort By Column to re-order the legend, but this may be difficult to do based on YTD value as there are some restrictions around how that can work.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy , @amitchandak 

 

Thanks for your quick help. 

 

I may want to change the chart as below excel format.  To sort by the amount for every category based on YTD , or it's OK to sort the amount for every category in each month. 

1.jpg

 

Thanks!

@Anonymous , I think legend sorting happens alphabetically. Check if there any idea https://ideas.powerbi.com/ideas/ 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak ,

Thanks for your reply. 

I may ask in another way, I know the legend sorting is not possible. 

What if I rank them in a table? and then sort them as the rank column? is it possible?

1.jpg

You could use RANKX to create a calculated column that ranks each category. You just have to make sure that each category only has 1 rank, so every year for that category and every month it must be the same number ranking. 



Then you can use Sort By Columns to sort the category by rank and the legend will automatically update.

https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column


You may also be interested in Ribbon chart, which shows relative rank for each category and how it has changed from month to month: https://docs.microsoft.com/en-us/power-bi/visuals/desktop-ribbon-charts 

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@Anonymous , I doubt you can do that for legends. Please check and vote for an idea.

https://ideas.powerbi.com/ideas/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.