Forum Discussion

rpiboy_1's avatar
rpiboy_1
Helper V
3 years ago
Solved

Dynamically Merge Multiple Columns

Hi all, I want to dynamically merge columns in a function.   Let's say I have this fairly 'standard' PQ expression:     #"Inserted Merged Column" = Table.AddColumn(#"PreviousStepp", "NewColumnN...
  • ppm1's avatar
    3 years ago

    Here is one way to do it. You can provide the colnames as a concatenated text string and parse it in the function.

     

    //fnAddMergeColumn
    let
        Source = (inputtable as table, newcolumn as text, colnames as text) => 
            let 
            
                result = Table.AddColumn(inputtable, "Concatenated", each Text.Combine(Record.ToList(Record.SelectFields(_, Text.Split(colnames, "-")) ), "."))
            in 
                result
    in
        Source