Forum Discussion
rpiboy_1
Helper V
3 years agoDynamically 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...
- 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
ppm1
Solution Sage
3 years agoHere 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
rpiboy_1
Helper V
3 years agook, this has me thinking... and I think this is kinda of what your code is doing.
I could use my Text list of of column names to isolate the columns I'm interested in merging into a seperate table, as a Table I should be able to just merge all the associate columns, then pass the merged values as a column back into my original table through a merge. Will tackle this further in the morning.