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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sorting Text Column As Extracted Numbers?

Hey all,

 

I have a column that looks something like this: AA1, AA2, AA10, AA12, AA20

 

When I sort the column however, it treats it as a text and does the following:

AA1

AA10

AA12

AA2

AA20

 

I need to instead order it as follows:

AA1

AA2

AA10

AA12

AA20

 

I am using a DirectQuery so I cannot use index columns. I also tried extracting the numbers from the column then sorting by that number column but I got a circular dependency error. The calculated column formula was :

NumExtract = if(LEFT(table[col], 2)="AA", (MID(table[col], 3, LEN(table[col])-1)), table[col])

 

Anyone know how I might be able to sort this column properly?

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

When I try and add in that measure column I get the below error. The format of the ranked column is Decimal Number though so I don't know why it would be treating it as Char or Currency.

JP2018_0-1628169845159.png

 

edit: I found the solution using my num extract column! I placed it at the top of the row list in the matrix, changed the format to whole number, then sorted the matrix by that column. In order to hide it, I changed the name of the column to "." and minimized the column width.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

Please create a measure as below and apply it onto the related visual. Then sort the visual data by this measure just as below screenshot....

Measure =
RANKX (
    ALL ( 'table' ),
    CALCULATE ( MAX ( 'table'[NumExtract] ) ),
    ,
    ASC,
    DENSE
)

yingyinr_1-1628146213052.png

Best Regards 

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

When I try and add in that measure column I get the below error. The format of the ranked column is Decimal Number though so I don't know why it would be treating it as Char or Currency.

JP2018_0-1628169845159.png

 

edit: I found the solution using my num extract column! I placed it at the top of the row list in the matrix, changed the format to whole number, then sorted the matrix by that column. In order to hide it, I changed the name of the column to "." and minimized the column width.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.