Forum Discussion

bullius's avatar
bullius
Helper V
9 years ago
Solved

Sort by another column error

Hi   I have categories that I want to sort. The data looks like this:   Category Sort Order A 1 A 1 A 1 B 3 B 3 B 3 C 2 C 2 C 2   To populate the sort...
  • KGrice's avatar
    KGrice
    9 years ago

    This is one of those time where I don't think the error message is entirely helpful, and I'm not even sure why it's an issue. What it really means is that you can't sort by a column that depends on the column you want sorted. You can see the same problem here in Power Query and Power Pivot.

     

    As a workaround, can you recreate the Sort Order in the Query Editor? If you go to Edit Queries, you can use the Add Custom Column feature in the Add Column tab in the ribbon. Use this formula:

     

    =if [Category]="A" then 1 else if [Category]="C" then 2 else if [Category]="B" then 3 else 0

     

    You have to end with an "else" which is the only reason I end with else 0. If you know you'll only have A, B, and C values in Category, it won't hurt anything, but neither will:

     

    if [Category]="A" then 1 else if [Category]="C" then 2 else 3

     

    That will create the Sort Order column. If you prefer a UI to writing the formula by hand, you can alternatively use the Conditional Column under Add Column:

     

     

    Once you Close and Apply, you can then go to the Data pane and sort your Category column by Sort Order.