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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Custom sorting ASC order

Hi all,

I need help with ordering the columns in ASC order correctly. Here is my data:

DayCodeNumber
1300-500-10C-11
2300-500-10C-1010
3300-500-10C-22
4300-500-10C-63
5103-300-23C-2020
6103-300-23C-2121
6180P-100-1C-PRPR
7135-100-1A-1010
8135-100-1A-1212
9135-100-1A-12r12r
10180-120-2B-88
11180-120-2B-99
1220S-200-9C-11
1320S-200-9C-1010
1420S-200-9C-22
1520S-200-9C-22
1620S-200-9C-33
1720S-200-9C-33
1719E-260-9B-PRPR
18135-101-1A-1010
19135-101-1A-10r10r
20130-200-6Y6Y


The columns are Day, Code and Number (made by the last symbols from Code). I need to order the Code column in ASC order, but with the following exceptions:
• The “PR” symbols at the end of Code (or in the Number column) should always populate on the top
• All codes in Code column should be ordered in ASC order and the numbers at the end should be ordered 1,2,3…not 1,10,2…
• All codes are separated in some sort of groups (300-500-10C-1, 300-500-10-2, 135-100-1A-10) and I need the numbers to be ordered ASC for every new group
• All codes ending with number&“r” should be shown after the same code without “r”

This is the desired result:

180P-100-1C-PRPR
19E-260-9B-PRPR
300-500-10C-11
300-500-10C-22
300-500-10C-66
300-500-10C-1010
103-300-23C-2020
103-300-23C-2121
135-100-1A-1010
135-100-1A-1212
135-100-1A-12r12r
180-120-2B-88
180-120-2B-99
20S-200-9C-11
20S-200-9C-22
20S-200-9C-22
20S-200-9C-33
20S-200-9C-33
20S-200-9C-1010
135-101-1A-1010
135-101-1A-10r10r
130-200-6Y6Y


*In the future there will be more different codes&numbers. The logic for PR, r, ASC order will remain the same.

I tried to add a new column with the following calculation:
Sort_Order =
IF (
NOT ( ISERROR ( 'Table'[Column] + 0 ) )
= TRUE ();
CONCATENATE ( REPT ( 0; 4 - LEN ( 'Table'[Column] ) ); 'Table'[Column] );
'Table'[Column]
)

But if I order the table by this column, only the Number column is sorted correctly, I cannot order the table by Code. And I need to be ordered by Code and then the Numbers to be correctly placed next to the code.

Do you have any suggestions if this is possible?

Thank you.

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

vxiaotang_0-1626244612821.png

vxiaotang_1-1626245176221.png

 

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Have you solved your problem? If yes, kindly accept the answer helpful as the solution(OR kindly share your solution). so the others can find it more quickly.😁

Or

if problem still persists, please let me know. Looking forward to receiving your reply.

 

 

Best Regards,

Community Support Team _Tang

v-xiaotang
Community Support
Community Support

Hi @Anonymous 

vxiaotang_0-1626244612821.png

vxiaotang_1-1626245176221.png

 

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors