Forum Discussion

vinothkumar1990's avatar
2 years ago
Solved

How to sort the values within a column in Power BI

Hi,

I have a column called Col1 which contian value like 456,123,789.

Meaning values within the column are seperated by comma. 

 

I want to sort the value like 123,456,789.

 

Note - Some columns can have any set of values e.g. 123,456,789 or 123,678 or 456,123,491,756.

 

Is there anyway to do the sorting winthin a column.

 

Thanks in advance!

 

  • Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(List.Sort(Text.Split([Values],","),Order.Ascending),","))
    in
        #"Added Custom"

    Hope this helps.

     

2 Replies

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion

    vinothkumar1990  - you'll have to split the data in the column. In Power Query when you split column by delimeter, you can expand the advanced options and split by rows. Then you could sort the column, and if you really needed to recombine you could merge the data back together using a group by and custom function.

  • Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Combine(List.Sort(Text.Split([Values],","),Order.Ascending),","))
    in
        #"Added Custom"

    Hope this helps.