Forum Discussion

dongho's avatar
dongho
New Member
5 years ago
Solved

Handling rows with multiple items

Dear power users.    I am struggling to handle rows with multiple items.   For example, the original table looks below(Some rows have multiple items on each columns)                 Column1    ...
  • v-alq-msft's avatar
    5 years ago

    Hi, dongho 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may try the following m codes in 'Advanced Editor'.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyizJTTWMycssSc01UtJRKkvMKQXxwTRIILGkBMgFkkZKsTog5am5xhDlJjDlxlDlJhDlxmDlJkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
        Custom1 = Table.TransformColumns(#"Changed Type",{{"Column1",each Text.Split(_,"#(lf)")},{"Column2",each Text.Split(_,"#(lf)")},{"Column3",each Text.Split(_,"#(lf)")}}),
        #"Added Custom" = Table.AddColumn(Custom1, "Custom", each let x = List.Count([Column1]) in
    List.Generate(
        ()=>0,
        each _<x,
        each _+1
    )),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
        Custom2 = Table.TransformRows(#"Expanded Custom",each 
    let c = [Custom] in
    [Column1=_[Column1]{c},Column2=_[Column2]{c},Column3=_[Column3]{c}]),
        #"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"Column1", "Column2", "Column3"}, {"Column1.Column1", "Column1.Column2", "Column1.Column3"}),
        #"Renamed Columns" = Table.RenameColumns(#"Expanded Column1",{{"Column1.Column1", "Column1"}, {"Column1.Column2", "Column2"}, {"Column1.Column3", "Column3"}})
    in
        #"Renamed Columns"

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps,then consider Accepting it as the solution to help other members find it faster.