Forum Discussion
Epression.Evaluate in combination with Text.Combine
- 2 years ago
And here is a modification using a list of columns as an additional argument:
(myTable as table, mergCols as list) => let #"Inserted Merged Column" = Table.AddColumn(myTable, "Merged", (r)=> Text.Combine( List.Transform( Record.FieldValues( Record.SelectFields( r,mergCols)), each Text.From(_,"en-BE")) ," | "), type text), Result= #"Inserted Merged Column" in ResultIf you named this : fn-CombineCols, you could call it like this in your main query:
#"Added HASH" = #"fn-CombineCols"(#"Changed Type", { "Capakey", "Partnumber", "Name", "Street", "Number", "Postcode", "Location", "Province", "StartDate", "EndDate" })Examining your existing code more closely, you have already type all of the columns as text. That being the case, you can remove from the function the List.Transform(...) and shorten to:
(myTable as table, mergCols as list) => let #"Inserted Merged Column" = Table.AddColumn(myTable, "Merged", (r)=> Text.Combine( Record.FieldValues( Record.SelectFields( r,mergCols)) ," | "), type text), Result= #"Inserted Merged Column" in Result
What is this doing that the Merge columns function in the GUI does not already do?
Select every column, right click on a column header, and click on Merge.
Alternatively, selecy all columns, go to Transform or Add Column --> Merge Columns.
- ronrsnfld2 years ago
Super User
It is allowing the list of columns to be merged to come from a list. As he wrote: "I want to mak this more dynamically. The list of columns should come from a powerquery list."
His actual code creates a number of hashes of different combinations of columns.