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
RickSchultz
Helper II
Helper II

Sort column with numbers and text

Hello!  I'm seen answers to this kind of question but the closest solutions don't seem to work, so I'm asking for help, please.

 

I have a data set with about 700,000 rows (and growing).  One column has responses to questions.  Not every row has a question, and not every question has a response, so there are lots of nulls.  As well, since new responses are being created fairly regularly, I can't just list every answer and sort them to use as a sort column.

 

I tried this promising answer:  https://community.powerbi.com/t5/Desktop/Number-sorting-in-text-format/m-p/237256; I also got an issue with the REPT part, but since my numbers are no more than 2 digits, I was able to just add a 0 to the first digit to try that as a sort order.  Unfortunately, when I tried to use that, I got a circular logic error.

 

Is there some other way to force Power BI to sort a number as a number, even if it's formatted as text?  Or another trick or workaround you've found helpful?

 

Thank you!

 

1 ACCEPTED SOLUTION
RickSchultz
Helper II
Helper II

Thanks, Polly.  I should have been more clear - I apologize.  I have some numbers (1, 2, 3 and so on) and some words/phrases (1-2 years, Usually, Strongly agree and so on) in a column:

1

Strongly Agree

3

10

Disagree

 

Of course, the plain numbers are sorting like text, 1, 10, 11, 12, 2, 3 ,4 and so on.  

 

As I dug in, I found there was a lot more that I needed to do to organize this, so I found this option for a bulk replace value - haven't tried it yet, but it looks promising:  https://www.howtoexcel.org/bulk-replace-values/#:~:text=When%20inside%20the%20power%20query,press%20....

View solution in original post

2 REPLIES 2
RickSchultz
Helper II
Helper II

Thanks, Polly.  I should have been more clear - I apologize.  I have some numbers (1, 2, 3 and so on) and some words/phrases (1-2 years, Usually, Strongly agree and so on) in a column:

1

Strongly Agree

3

10

Disagree

 

Of course, the plain numbers are sorting like text, 1, 10, 11, 12, 2, 3 ,4 and so on.  

 

As I dug in, I found there was a lot more that I needed to do to organize this, so I found this option for a bulk replace value - haven't tried it yet, but it looks promising:  https://www.howtoexcel.org/bulk-replace-values/#:~:text=When%20inside%20the%20power%20query,press%20....

v-rongtiep-msft
Community Support
Community Support

Hi @RickSchultz ,

I have created a simple sample, please refer to it to see if it helps you.

Create a column first.

NumExtract =
IF (
    LEFT ( 'Table'[Column1], 2 ) = "AA",
    ( MID ( 'Table'[Column1], 3, LEN ( 'Table'[Column1] ) - 1 ) ),
    'Table'[Column1]
)

Then create a measure.

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

vpollymsft_0-1649658926249.png

If I have misunderstood your meaning, please provide your pbix file without privacy information and your desired output.

 

Best Regards

Community Support Team _ Polly

 

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

 

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.