Forum Discussion
Sort by another column error
- 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.
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.
Unfortunately I won't be able to use Custom column from Edit queries as my Table is created in Power Bi using New Table. I cannot see this in edit Query editor. When I use New column in VI editor to create sort column. Its thrwoing the error.