PQ Dynamic Add Merge Column

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
In Power Query, how can I add a column which merges columns based on a list (so the list of column names gets merged)?


If done manually, I would have


Code:
let
    Source = Input_Original,
    #"Added Key" = Table.AddColumn(Source, "Key", each
        Text.Combine(
            { [Column1], [Column2], [Column3], [Column4] },
            " - "
        ))
in
    #"Added Key"
Instead, I want that list of Column1...Column4 to be a list that I feed into Text.Combine, but since it's referencing columns, it doesn't work to just provide a list


Code:
{"Column1", "Column2", "Column3", "Column4"}
I tried the following method, but it is extremely slow (the manual method loads in 2-3 seconds, this method takes minutes)


Code:
let
    Source = Input_Original,
    #"Added Key" = Table.AddColumn(Source, "Key", each
        Text.Combine(
            Record.FieldValues(Record.SelectFields(_, KeyColumns_List, MissingField.Ignore)),
            " - "
        ))
in
    #"Added Key"
There must be a better (faster) way?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
How are you creating KeyColumns_List ?

KeyColumns_List is an Excel table loaded to Power Query (and then converted to a list). The idea is that I want to make it easier for users to maintain the columns that should be merged to create a "Key" column (sometimes new columns need to be added to change it).
 
Upvote 0
when you create KeyColumns_List , try to do KeyColumns_List = List.Buffer(Your_Code_To_Load_The_List)


​does it make it faster?
 
Upvote 0
when you create KeyColumns_List , try to do KeyColumns_List = List.Buffer(Your_Code_To_Load_The_List)


​does it make it faster?

Wow, that made all the difference. Same speed as the original now. Thanks!
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,974
Members
448,537
Latest member
Et_Cetera

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top