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
bullius
Helper V
Helper V

Sort by another column error

Hi

 

I have categories that I want to sort. The data looks like this:

 

CategorySort Order
A1
A1
A1
B3
B3
B3
C2
C2
C2

 

To populate the sort order column, I wrote the following formula:

 

Sort Order =

    IF ( [Category] = "A", 1,

    IF ( [Category] = "C", 2,

    IF ( [Category] = "B", 3)))

 

Then, I tried to use the "Sort by Column" tool to sort the Category column by the Sort Order column, but the following error message occured:

 

Sort Error.png

 

Anyone know how the reason for this and how to resolve?

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

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:

 

Category.PNG

 

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

View solution in original post

13 REPLIES 13

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.