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

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
Super User
Super User

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!




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
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.

Top Solution Authors