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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

I want to sort text and number


The image below shows: Product 1, Product 10, Product 100. But I want you to order and stay: Product 1, Product 2, Product 3 ...

 

foto 5.png

3 REPLIES 3
dax
Community Support
Community Support

Hi FABRICIOWF12, 

You could try below M code to create column, then click [Name] column to set Sort by.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKlAwVIrVAdFGUNoYSptAaUMDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "name", "name - Copy"),
    #"Removed Columns" = Table.RemoveColumns(#"Duplicated Column",{"name - Copy"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([name]),each if Value.Is(Value.FromText(_), type number) then _ else null)))),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}})
in
    #"Changed Type1"

Best Regards,
Zoe Zhi

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

Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,

Put your table in the order you wish it to be, add an index column, and then sort the product column by that index column.  The same applies to sorting Month Names.

 

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

if you're unable to put the table in a desired order (which the above index suggestion solves very easily)...then you can also try chopping up the produto column and separate the name from the number.  For example:

 

Duplicate the product name column, and then modify the duplicated column to replace values (right mouse click on the column) and in the "Value to find" cell, enter "Producto " and for the "Replace with" cell, leave it blank.  You'll then have the product number only associated with the full product name.  then you can change that column to a whole number, and then sort from smallest to biggest.  That should do it too.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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