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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
amhiggins
Frequent Visitor

Sort Legend by Chart Value

Hello,

 

I have a line chart showing the running count of sometime over time per category. There happen to be a lot of categories in my data set which is out of my control. Here is an example plot with the category names withheld (for security purposes). 

 

amhiggins_0-1633528180876.png

 

What I want is for the legend on the right to be sorted with the category with the highest value at the top - so the top line (as ordered by the current total) in the chart is also the top category listed in the legend, the second line is the second category listed, etc. 

 

I tried creating a summary table with the value counts (code below) and then using that to custom sort the category column but I get a circular dependency error because I'm using the category column to create the summary table. 

Category Sort Table = 
SUMMARIZE(table, table[Category], "count", CALCULATE(DISTINCTCOUNT(table[id])))

 

Is there a way to achieve this type of legend sorting? Am I missing something?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @amhiggins ,

I created some data:

vyangliumsft_0-1634028531805.png

Here are the steps you can follow:

1. Enter the Power query, click Table, and click Copy to form Table2.

vyangliumsft_1-1634028531809.png

2. In Table 2, Home – Group By.

New column name – Max.

Operation – Max.

Column – amount.

vyangliumsft_2-1634028531813.png

3. Select the newly appeared [Max] and select Sort Descending.

vyangliumsft_3-1634028531815.png

4. Add Column – Index Column –From 1.

vyangliumsft_4-1634028531818.png

5. Place [Qtr] of Table in Axis, [amount] of Table in Values, and [group] of Table2 in Legend.

vyangliumsft_5-1634028531820.png

6. Click [group] of Table2, Column tools – Sort by column – Index.

vyangliumsft_6-1634028531823.png

7. Result.

Here it will be sorted with Index.

vyangliumsft_7-1634028531823.png

 

Best Regards,

Liu Yang

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @amhiggins ,

I created some data:

vyangliumsft_0-1634028531805.png

Here are the steps you can follow:

1. Enter the Power query, click Table, and click Copy to form Table2.

vyangliumsft_1-1634028531809.png

2. In Table 2, Home – Group By.

New column name – Max.

Operation – Max.

Column – amount.

vyangliumsft_2-1634028531813.png

3. Select the newly appeared [Max] and select Sort Descending.

vyangliumsft_3-1634028531815.png

4. Add Column – Index Column –From 1.

vyangliumsft_4-1634028531818.png

5. Place [Qtr] of Table in Axis, [amount] of Table in Values, and [group] of Table2 in Legend.

vyangliumsft_5-1634028531820.png

6. Click [group] of Table2, Column tools – Sort by column – Index.

vyangliumsft_6-1634028531823.png

7. Result.

Here it will be sorted with Index.

vyangliumsft_7-1634028531823.png

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@amhiggins , as of now legend can sort ascending or on a sort column

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

And it is not possible to create a sort column in this situation?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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