Forum Discussion
Dynamically Merge Multiple Columns
- 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
Hi rpiboy_1
I don't see the advantage of creating another function to do this. At some point you have to declare what ColumnNamesList is so not sure how 'dynamic' your desired solution is.
Why not just concatenate the columns ?
= [Column1] & "." & [Column2]
Regards
Phil
FYI, to close the loop on this. I did not end up writing this as a seperate function, but it was helpful to see the solution written as a stand-alone function from the perspective of parsing the code to understand how to adopt it to my own needs.
I was actually able to drop the 'Text.Split' as in my real function I already have the columns names as list, so conviently I'm able to just pass that list directly and it all works!
Thanks again!