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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
justlogmein
Helper III
Helper III

How to use a comma seperated path to sort rows in the same order

I have a column called QPath_Old that contains a comma seperated path for each part. I would like to sort each part in this order based on the values in the Old Process Step ID column.

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zZhBa8JAEEb/S8572WxiJkdBeyhFpFfxIMVCQCpo+v87cSMhCHY8zTsMazaCj+8xyay7XbE9XPqYmiIUb93pdLwk/bRaxrBallop5N04ruW43verca3D+++17767r0PfnX/i/LKcX6awWUetUqvSqrUWYXPuj9fw+RG1Sq1U7MMdTwB46+YpYgtAfII3Ca6IeALAMwtGJjgI1l0imjijGcRCk5u6FoknADxz1yITnATXRDwB4JkFIxOcBEcingDwzIKRCQ6C9btENHFGM4iFJpelIt8Y4oxmkopMLk/IyNOZOKOZJmRkck2GIqKJM5pBKjS53KlINHFGM3UqMrncqciHiDijmToVmVwelLAnLwUiorVctCwU+QARZzTT5ItMLktdENFaLtotteE+EU7c4SztQE1vUDv/ASKlcCgNsiGkr1hHjlQP1tFzKYT0FevIuevBOvofPgjpv0c6bIjifG4yzbLIY504D4wmsQ0Mb/8H", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PARTID = _t, #"Old Process Step ID" = _t, QPath_Old = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"PARTID", type text}, {"QPath_Old", type text}}),
    SortedRows = Table.Sort(ChangedType,{{"PARTID", Order.Ascending}}),
    PartIndex = Table.AddIndexColumn(Table.Distinct(Table.SelectColumns(SortedRows,{"PARTID"})), "Index", 1, 1, Int64.Type),
    MergePartIndex = Table.NestedJoin(#"SortedRows", {"PARTID"}, PartIndex, {"PARTID"}, "PartIndex", JoinKind.Inner),
    ExpandPartIndex = Table.ExpandTableColumn(MergePartIndex, "PartIndex", {"Index"}, {"Part Index"})
in
    ExpandPartIndex

 

 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @justlogmein ,
adding a column with this formula should do the trick:

List.PositionOf(Text.Split([QPath_Old], ","), [Old Process Step ID])

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi @justlogmein ,
adding a column with this formula should do the trick:

List.PositionOf(Text.Split([QPath_Old], ","), [Old Process Step ID])

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors