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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
tearless
Regular Visitor

Hierarchy sorting

tearless_0-1725503084712.png

I have a hierarchy above in my report and it goes down to level 9. 

I also have a reporting order ID tagged at level 1 and when I try to sort this, it shows the following error. 

tearless_1-1725503161217.png

 

From level 1 to level 9, it should be sorted in a specific order and I don't know how to do this.. 

Can someone please help?

5 REPLIES 5
PijushRoy
Super User
Super User

Hi @tearless 

Please add SortOrder column for each 9 columns in your database
or use Power Query conditional column to add a SortOrder Column.

PijushRoy_0-1725505877365.png

 






Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





This is what I did. 

 

I created hierarchy tables Level1... to Level 9 with ID that shows the order of each hierarchy member. 

Then I joined these 9 tables with the data table which has those hierarchy member. 

Then, I selected each hierarchy table and sorted by those IDs.. 

 

But the report still does not get sorted as needed. 

tearless_0-1725617690719.png

 

 

Ritaf1983
Super User
Super User

Hi @tearless 

To sort a hierarchy properly in Power BI, you need a separate sort column for each level of the hierarchy. In your case, since the hierarchy goes down to 9 levels, you should create individual sort columns for each level. These sort columns will define the specific order for each hierarchy level.

Example:

Let's assume your hierarchy has the following levels:

  • Level 1: ReportingLevel01
  • Level 2: ReportingLevel02
  • ...
  • Level 9: ReportingLevel09

You need to create sort columns like:

  • SortLevel01 for ReportingLevel01
  • SortLevel02 for ReportingLevel02
  • ...
  • SortLevel09 for ReportingLevel09

Each sort column should have a unique value for each row to define the sorting order for that level.

Once you have these sort columns, you can set the sorting for each hierarchy level in Power BI by going to the column tools and selecting "Sort by Column" and choosing the appropriate sort column for each hierarchy level.

By doing this, you ensure that each level of the hierarchy is sorted in the desired order.

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

This is what I did. 

 

I created hierarchy tables Level1... to Level 9 with ID that shows the order of each hierarchy member. 

Then I joined these 9 tables with the data table which has those hierarchy member. 

Then, I selected each hierarchy table and sorted by those IDs.. 

 

But the report still does not get sorted as needed. 

tearless_0-1725612257054.png

 

 

Hi @tearless 
If you’ve correctly defined a sort order for each level in the hierarchy (numeric, which is required), sorted all the tables, and placed the dimensions from the relevant tables into the visualization, with the visualization itself sorted by what’s in the 'Rows', it should work. If it’s not working, something must have gone wrong along the way. To figure it out, I’d need to see the file. Please share a link to it (without sensitive data), and I’ll be happy to check it. Alternatively, I’m attaching a file I created for you with 4 hierarchies—this is enough to understand the logic, as it’s not dependent on the number of levels in the hierarchy.

Ritaf1983_0-1725619492451.pngRitaf1983_1-1725619531520.pngRitaf1983_2-1725619550353.png

Results :

Ritaf1983_3-1725619614930.png

+ you can download the pbix and follow my steps

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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