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
dkinchit
New Member

Sorting Legend in a Line Chart

Problem: I cannot sort the legends based on the chosen category's sales proportion, PBI does it based on alphabetical order. Strange given you would have expected this to occur by default like excel. The idea is that whatever category/legend is selected (segment, brand or nameplate etc.), it is able to sort itself in descending order of % sales.

So Far: 
a) If I try to sort by clicking on the menu on the top right hand corner, and selecting 'Sort by % Sales', then it sorts the months on the X-Axis instead.
b) If I use Visual Level Filters, go to Sales, select 'Top N' and select Top 5, while it does hide the remaining Segments, it also recalculates the '% Sales' which gives the incorrect proportions.

How do I sort the legend by value AND show only a select set of things (e.g. maybe Top 5 Segments, but then it could be a chart that has select set of key brands etc.)?

Measure: % Sales = [Monthly Total]/CALCULATE([Monthly Total],ALLSELECTED())

 

 Sales Table.PNGCapture.PNGCapture.PNG

7 REPLIES 7
Greg_Deckler
Super User
Super User

So, you need to create a numeric column that has them in the desired numeric order and then change the Sort By column of your alphanumeric column to that new numeric column.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler - tks a lot for the quick reply. Actually I've been tracking this for many days and have seen replies on this, some of them from you too 🙂

 

The problem I face is, I want to do this dynamically. The sales data gets updated monthly. So the next month if any of this ordering was to change, how do I build that column to account for that? Lastly, in this chart it's car segments (e.g. Compact Car, Compact SUV etc.). If I am making the same chart for say brands (Chevy, Ford, Honda etc.) is there a way that the 'numeric column' you mentioned, can account for it?

 

Or what would you suggest as a turnaround?

 

Tks again for your time!

If you are looking for the last reported month ranking, you could add calculated column which would use data using filter of last month from today's month. 
It should work for your categorical filters as well. It will not work for date filters if you need them.

@alena2k - Tks! As you can guess I am still a newbie so would appreciate if you could post a sample formula of sorts of how I would define that new column?

 

Appreciate your time!

I hope that something like this will help you:

 

Last Reported Rank =

          RANKX(Categories,
                          CALCULATE(SUM('Sales'[Sales]), 'Sales'[Date] > EOMONTH(NOW(), -1),'Sales'[Date]<= EOMONTH(NOW(), 0))
         ,,DESC)

I assume that yiy have Caregories table where you can setup sorting by this column.

 

Thanks @alena2k...sorry I just saw this so will try this now. Will update soon.

Any luck with the solution provided? I have been trying to solve (almost ) the exact same problem for last couple of weeks and can't seem to hit it right. I try sorting by column but it gaveme an error

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.