Forum Discussion

Ju7438's avatar
Ju7438
Regular Visitor
3 years ago
Solved

Unfold a path to lines

Hello Everyone,    Im currentky struggleling with Power BI, here is the situation, i have a table with 1 column containing multiple path with "/" as separator. e.i :   Context A/B/C A1/...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Ju7438 

    For your need , i can be realized in Power Query Editor.

    You can put this M code in "Advanced Editor" to refer to :

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctR30ndWitUBsgz1HY30HY31HU2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Context = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Context", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>Text.Split(x[Context],"/")       ),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom2", (x)=>    
     Table.AddColumn(Table.FromColumns({{0..List.Count(x[Custom])-1}}),"test",(y)=>   Text.Combine(List.Range(x[Custom],0,y[Column1]),"/") )[test]      
      ),
        Custom1 = Table.FromColumns({List.Combine(#"Added Custom1"[Custom]) ,  List.Combine(#"Added Custom1"[Custom2])})
    in
        Custom1

     

    Then we can meet your need:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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