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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors