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
aburling1989
Frequent Visitor

Sort column by multiple columns

Hi,

 

I was wondering if it was possible to sort a column based on two columns?

 

In the example below I'm trying to sort the Category by the Sort_Order column. The problem is that the sort order is different for the same values within each group. Ideally what I'm looking for is to sort the category by the Sort_Order within each group. Is this possible?

 

GroupCategorySort_Order
1Large1
1Small2
1Medium3
2Small1
2Medium2
2Large3

 

I appreciate any help with.

 

Many thanks,

Ash

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @aburling1989 ,

 

You could create a rank column to sort category.

Rank =
RANKX ( 'Table', 'Table'[Group] * 10 + 'Table'[Sort_Order],, ASC, DENSE )

2-1.PNG 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

7 REPLIES 7
v-eachen-msft
Community Support
Community Support

Hi @aburling1989 ,

 

You could create a rank column to sort category.

Rank =
RANKX ( 'Table', 'Table'[Group] * 10 + 'Table'[Sort_Order],, ASC, DENSE )

2-1.PNG 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
az38
Community Champion
Community Champion

@aburling1989 

also, you can check here https://www.c-sharpcorner.com/article/how-to-sort-a-table-using-multiple-columns-in-power-bi/ to understand how to sort Table visual by a multiple columns (hint: use Shift + Click)


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
az38
Community Champion
Community Champion

Hi @aburling1989 

If I understand you correct you can create a Surrogate Order Column and try to sort by it, like

Surrogate Order Column = 
CONCATENATE(Table[Group], CONCATENATE("_", Table[Sort_Order]) )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @az38 ,

 

Many thanks for the quick response. The problem is the values in the 'Category' column are not unique, so even if I concatenate the 'Group' and 'Sort' columns I still get this error message: "There can't be more than one value in 'Category' for the same value in 'Surrogate Order Column'.

 

If I concatenate the 'Group' and 'Category' column it would work as they become unique values but I want to avoid doing that if possible.

 

Many thanks,

Ashley

 

 

 

@aburling1989 

Do you create measure or column?

If column, there shouldn't be such error


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @az38 ,

 

I added it as a column and it certainly sorts the data correctly; However the issue I still have is that I can't specifically sort the 'Category' by this column. So if I was to add 'Category' to a slicer it still defaults the sort order alphabetically, but I would want it sorted by the new 'Surrogate Order Column'.

 

Thanks again for your help.

Ashley

@aburling1989 

try this technique https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.