Forum Discussion

jerryr125's avatar
jerryr125
Helper IV
1 year ago
Solved

Power Query - create multiple rows

Hi - I would like to do the following - create a row for each value in a field.   Example:   ID Food Type 1 Ice Cream; Cake; Cookies 2 Apples; Bananas; Pears; Peaches 3 Pizza ...
  • ronrsnfld's avatar
    1 year ago

    Source

     

     

    You turn the string into a List, and then expand it:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJMTlVwLkpNzLVWcE7MTgWS+fnZmanFSrE60UpGQAWOBQU5qcXWCk6JeUAIZASkJhZBqOQMqDpjoLqAzKqqRKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Food Type" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Food Type", type text}}),
        #"Create List" = Table.TransformColumns(#"Changed Type",{"Food Type", each Text.Split(_,";"),type {text}}),
        #"Expanded Food Type" = Table.ExpandListColumn(#"Create List", "Food Type")
    in
        #"Expanded Food Type"

     

    Result

     

     

     

  • AntrikshSharma's avatar
    1 year ago

    jerryr125 Many ways to solve this, here is one using List.TransformMany

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJMTlVwLkpNzLVWcE7MTgWS+fnZmanFSrE60UpGQAWOBQU5qcXWCk6JeUAIZASkJhZBqOQMqDpjoLqAzKqqRKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Food Type" = _t]),
        ChangedType =
            Table.TransformColumnTypes ( Source, { { "ID", Int64.Type } } ), 
        Transform = 
            List.TransformMany (
                Table.ToRows ( ChangedType ), 
                ( z ) => Text.SplitAny ( z{1}, ";" ), 
                ( x, y ) => { x{0}, y }
            ), 
        ToTable = 
            Table.FromRows ( 
                Transform, 
                type table [ ID = Int64.Type, Food Type = text ] 
            )
    in
        ToTable

     

  • Omid_Motamedise's avatar
    1 year ago

    Hi jerryr125 , you can solve this problem by UI, just select the column Food Type, go to the homw tab, select Split Column by delimiter and make the setting presented in the below picture (it is important to select by row)