Search code examples
excelpowerbipowerquerymcustomcolumn

Multiple Columns in One Step in Power Query


I want to add multiple columns in one step only.

I was able to find a custom function below.

 Table.FromColumns(
        Table.ToColumns(#"Removed Other Columns1") & {{null},{null}},
        Table.ColumnNames(#"Removed Other Columns1") & {"NewCust1","NewCust2"}
        )

It will add 2 columns with null on each cells however what I want to do is that all new columns is equal to an existing Column called Source.Name.


Solution

  • This is an easier way.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoC4mSl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Source.Name = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
        #"Added Custom" = Table.ExpandRecordColumn( Table.AddColumn(#"Changed Type", "Custom", each  [NewCust1=[Source.Name], NewCust2=[Source.Name]]), "Custom", {"NewCust1", "NewCust2"})
    in
        #"Added Custom"