Forum Discussion

aburling1989's avatar
aburling1989
Frequent Visitor
6 years ago
Solved

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

  • Hi aburling1989 ,

     

    You could create a rank column to sort category.

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

     

     

7 Replies

  • az38's avatar
    az38
    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]) )
    • aburling1989's avatar
      aburling1989
      Frequent Visitor

      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

       

       

       

      • az38's avatar
        az38
        Community Champion

        aburling1989 

        Do you create measure or column?

        If column, there shouldn't be such error

  • v-eachen-msft's avatar
    v-eachen-msft
    Community Support

    Hi aburling1989 ,

     

    You could create a rank column to sort category.

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