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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
LP2803
Responsive Resident
Responsive Resident

Order Legend in a line chart

Hi all,

 

I guess my requirement is simple but not able to get through.

 

I have a line chart with years added in the legend and months added in X axis. the legend currently shows 2018, 2019, 2020. 

 

I would like to get the legend in reverse order like 2020, 2019, 2018.  any thoughts please....

 

LP2803_0-1597147801408.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@LP2803 , Create a desc Rank on year and mark it as sort column

New columns

Year 1 = [Year]

Year Rank = Rankx(all(Table), [Year],,desc,dense)

 

sort Year 1 on Year rank and use year 1

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

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@LP2803 , Create a desc Rank on year and mark it as sort column

New columns

Year 1 = [Year]

Year Rank = Rankx(all(Table), [Year],,desc,dense)

 

sort Year 1 on Year rank and use year 1

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

I get an error "a circular dependency was detected: "

LP2803
Responsive Resident
Responsive Resident

Ok. when i use the column name instead of the Table in All(table) i get the result.

 

But i have new issue now. when i go to modeling click on sort by column it  show the below error. How can i fix this.

 

Sort by another column 

This column can't be sorted by a column that is already sorted, directly or indirectly, by thi column.

LP2803
Responsive Resident
Responsive Resident

Got it! 

 

I derived the Year1 column from a different data field and then the sorting worked.

 

Thanks a lot. It is a great help.

Daviejoe
Memorable Member
Memorable Member

This should work for you

 

https://community.powerbi.com/t5/Desktop/Modify-the-legend-order/m-p/25338#M8261





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




LP2803
Responsive Resident
Responsive Resident

Thanks for the reply.

 

I cant create different measure as its not suitable in my case.

for the second solution provided as below, i dont find any arrow or field in the legend pane. as mentioned in the step two below.

 

Could you please add a picture or screenshot where i can find it?

 

1) Select your visual.

2) In the Legend pane, select the arrow next to the field that you want to reorder.

3) Select New Group.

4) Create a name for your group (Power BI will populate one by default).

5) Use the group dialogue to create a separate group for each attribute value that you want to appear separately in the visual. You can group attribute values or keep them separate by creating a group for each one. There's also a handy "Include Other group" option that groups any remaining attribute values into an "Other" category if you don't need them broken out.

6) Since Power BI orders the legend alphabetically, if you rename the groups and place a number in front of each one indicating the order in which you want it to appear ("1)" or "1-" or "1:" for example), Power BI will display the groups in ascending order based on the leading digit.

 

Power BI also allows you to reuse the grouping you created in other visuals. It's a really handy way to reorder the attributes if you don't mind there being a number in front of each item in your legend.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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