Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
akhaliq7
Post Prodigy
Post Prodigy

sort a calculated table

I have created a calculated table and would like to sort it using one of the numeric columns following is my code:

 

Measure = 
 ADDCOLUMNS(
    FILTER(
        VALUES(Table[Column1]),
        'Table'[Column1] <> "Not Provided"
    ),
    "Status", Table[Column1],
    "Color", SWITCH('Table'[Column1], "sold", 1, "delivered", 2, "cancelled", 3, 4)
)

 

How do I add ORDER BY to the above code?

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @akhaliq7 ,

 

Hope everything is going well.

 

Based on your description, it can be seen that you want to rename the existing column1 to "Status", then assign different Colors to different Statuses, and finally sort according to Color.

 

To achieve your needs, please follow my steps below.

 

Enter Power Query to perform data cleaning, for example, rename Column1 to Status, select the Status column and right-click the two options in the screenshot below.

vhuijieymsft_0-1707288144270.png

 

Add Column>>Conditional Column

vhuijieymsft_1-1707288144273.png

 

After setting, click Close and Apply.

 

The ORDER BY function is used in DAX queries, and the syntax is as follows:

 

At this point, you can sort the Status by color. The default is ascending order.

 

pbix file is attached.

 

If you have any other questions please feel free to contact me, thank you for your patience and waiting.

EVALUATE
     ADDCOLUMNS(
         FILTER(VALUES('Table'[Status]),'Table'[Status] <> "Not Provided"),
         "Color", SWITCH('Table'[Status], "sold", 1, "delivered", 2, "cancelled", 3, 4)
     )
ORDER BY [Color]

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

Anonymous
Not applicable

Hi @akhaliq7 ,

 

Thank you very much for your reply.

 

I think you need to follow the steps below and then you can use EVALUATE.

 

First, select File>>Options and Settings>>Options>>Preview features>>DAX query view.

vhuijieymsft_0-1708489847587.png

 

After enabling this feature, restart your Power BI Desktop.

 

At this point, the function tab on the left has this.

vhuijieymsft_1-1708489847588.png

 

Now you can put my expression in here and run it.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @akhaliq7 ,

 

Hope everything is going well.

 

Based on your description, it can be seen that you want to rename the existing column1 to "Status", then assign different Colors to different Statuses, and finally sort according to Color.

 

To achieve your needs, please follow my steps below.

 

Enter Power Query to perform data cleaning, for example, rename Column1 to Status, select the Status column and right-click the two options in the screenshot below.

vhuijieymsft_0-1707288144270.png

 

Add Column>>Conditional Column

vhuijieymsft_1-1707288144273.png

 

After setting, click Close and Apply.

 

The ORDER BY function is used in DAX queries, and the syntax is as follows:

 

At this point, you can sort the Status by color. The default is ascending order.

 

pbix file is attached.

 

If you have any other questions please feel free to contact me, thank you for your patience and waiting.

EVALUATE
     ADDCOLUMNS(
         FILTER(VALUES('Table'[Status]),'Table'[Status] <> "Not Provided"),
         "Color", SWITCH('Table'[Status], "sold", 1, "delivered", 2, "cancelled", 3, 4)
     )
ORDER BY [Color]

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

I tried doing this but did not work and also when creating a calculated table cannot use evaluated, can only use evaluate in dax studio

Anonymous
Not applicable

Hi @akhaliq7 ,

 

Thank you very much for your reply.

 

I think you need to follow the steps below and then you can use EVALUATE.

 

First, select File>>Options and Settings>>Options>>Preview features>>DAX query view.

vhuijieymsft_0-1708489847587.png

 

After enabling this feature, restart your Power BI Desktop.

 

At this point, the function tab on the left has this.

vhuijieymsft_1-1708489847588.png

 

Now you can put my expression in here and run it.

 

If you have any further questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

lbendlin
Super User
Super User

I wouldn't want to call my calculated table "Measure" 🙂

 

Just add the ORDER BY at the end.

I changed the names for this question don't like to share internal workings at my company

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.