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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
wcarter
Helper I
Helper I

Sort legend by value of legend items?

I have a line chart with monthly granularity over a year. I need the legend at the top of the chart to sort by the count of items in each category and for the tooltip to sort by count of items in each category at the monthly level. I tried creating a rank column that has the desired granularity for monthly but it breaks the line chart, and if I try the yearly level the tooltip is out of order. If I try to sort the category column itself by the monthly column I get the error about not having multiple values in Y for sorting X. Is there any way to sort the legend by the values and not the categories?

 

Current tooltip/legend:

A2
B5
C1
D3

 

Desired tooltip/Legend

B5
D3
A2
C1
1 ACCEPTED SOLUTION
Oldnewbie
Frequent Visitor

PowerBI has enabled this functionality in the Visualisations pane now.

Here is how to do it.

1) Go to Columns:

Oldnewbie_0-1706857187871.png

2) Under Layout, turn 'Sort by value' to ON

Oldnewbie_1-1706857311086.png

3) You may choose to reverse order to keep largest quantity at bottom and smallest at top.

 

 

View solution in original post

8 REPLIES 8
Oldnewbie
Frequent Visitor

PowerBI has enabled this functionality in the Visualisations pane now.

Here is how to do it.

1) Go to Columns:

Oldnewbie_0-1706857187871.png

2) Under Layout, turn 'Sort by value' to ON

Oldnewbie_1-1706857311086.png

3) You may choose to reverse order to keep largest quantity at bottom and smallest at top.

 

 

Looks like this works for sorting within the column, but does not reflect in the legend order. Anyone know how to sort the legend by value as well?

v-angzheng-msft
Community Support
Community Support

Hi, @wcarter 

You can use sort  column by another column feature; furthermore, you can also create a custom sort order by creating a new sort column. Then use the visual option "Sort Legend".
You can refer to the following blogs and videos to help you.
Sort Legend Power BI Feature Tutorial And Review

Sort Legend Tutorial And Review - Power BI November 2021 Updates

 

vangzhengmsft_2-1648517666616.png

 

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

So the problem I have with this is that my Values on my line chart is a Count of the values in another column, and that second column has many duplicate values which gives me the error that 'There can't be more than one value in Column A for the same value in Column B" if I try to use it as the Sort By for Column A.

 

See below the issue I have with the Legend/Tooltip behavior, it only sorts by alphabetical of the legend items, I need to sort by value of the legend items:

sort-desired.jpg

 

Thank you!

please provide sample data as requested. Include a filter column so that we can create a measure based solution.

Here's a PBIX with sample data that fits the pattern I am working with. I need to sort Animal by Count of Sequence in the Tooltip so that when you hover over the line chart the items are in order of the values and not alphabetical, as indicated in my graphic. Thank you.

 

https://ufile.io/owksjf0j

@wcarter Thank you for providing the sample data. That helps a lot with proposing a potential solution.

See attached for a possible implementation with tooltip pages.

lbendlin
Super User
Super User

You can only sort a column by another column. If you want to sort a visual by a measure then you need to put that measure in the visual, or in the tooltips area.

 

Please provide sanitized sample data that fully covers your issue.

Please show the expected outcome based on the sample data you provided

 

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.