<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamically Merge Multiple Columns in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2939533#M92829</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 16:06:17 GMT</pubDate>
    <dc:creator>rpiboy_1</dc:creator>
    <dc:date>2022-11-30T16:06:17Z</dc:date>
    <item>
      <title>Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2936899#M92742</link>
      <description>&lt;P&gt;Hi all, I want to dynamically merge columns in a function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have this fairly 'standard' PQ expression:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#"Inserted Merged Column" = Table.AddColumn(#"PreviousStepp", "NewColumnName", each Text.Combine({[Column1], [Column2]}, "."), type text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Column1&lt;/TD&gt;&lt;TD&gt;Column2&lt;/TD&gt;&lt;TD&gt;NewColumnName&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A.B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;C.D&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I'd like to make this expression dynamic in a function where I pass the columns to be merged. So the code might look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(ColumnNamesList as list) =&amp;gt;

#"Inserted Merged Column" = Table.AddColumn(#"PreviousStepp", "NewColumnName", each Text.Combine(ColumnNamesList, "."), type text)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that Text.Combin expects an explict column name reference bracketed i.e. '[Column1]'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whereas the list will pass a list of Text values that are not converted to expclit column references (even if brackets are included)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e. this list will not work&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;List&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;[Column1]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;[Column2]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will be passed as {"[Column1]", "[Column2]"} and Text.Combine will fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I dymically pass a list of column name references that will function with the Text.Combine and respect the 'each' iterator for the rows? Normally I would use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Record.Field(_, varColumnName)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I don't know how to dynamically expand that expression to iterate Record.Field over each Column in the list?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 21:36:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2936899#M92742</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2022-11-29T21:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937188#M92751</link>
      <description>&lt;P&gt;Here is one way to do it. You can provide the colnames as a concatenated text string and parse it in the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//fnAddMergeColumn
let
    Source = (inputtable as table, newcolumn as text, colnames as text) =&amp;gt; 
        let 
        
            result = Table.AddColumn(inputtable, "Concatenated", each Text.Combine(Record.ToList(Record.SelectFields(_, Text.Split(colnames, "-")) ), "."))
        in 
            result
in
    Source&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 01:52:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937188#M92751</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2022-11-30T01:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937222#M92753</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452756" data-lia-user-login="rpiboy_1" class="lia-mention lia-mention-user"&gt;rpiboy_1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see the advantage of creating another function to do this.&amp;nbsp; At some point you have to declare what ColumnNamesList is so not sure how 'dynamic' your desired solution is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just concatenate the columns ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;= [Column1] &amp;amp; "." &amp;amp; [Column2]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phil&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 02:03:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937222#M92753</guid>
      <dc:creator>PhilipTreacy</dc:creator>
      <dc:date>2022-11-30T02:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937239#M92754</link>
      <description>&lt;P&gt;ok, this has me thinking... and I think this is kinda of what your code is doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 02:12:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2937239#M92754</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2022-11-30T02:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2939485#M92824</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="443516" data-lia-user-login="ppm1" class="lia-mention lia-mention-user"&gt;ppm1&lt;/a&gt;&amp;nbsp;brilliant! I should be able to adopt this. Fresh eyes in the morning helps. I was missing the combination of Record.ToList, SelectFields with a Text.Split.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks much!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 15:50:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2939485#M92824</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2022-11-30T15:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically Merge Multiple Columns</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2939533#M92829</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 16:06:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Dynamically-Merge-Multiple-Columns/m-p/2939533#M92829</guid>
      <dc:creator>rpiboy_1</dc:creator>
      <dc:date>2022-11-30T16:06:17Z</dc:date>
    </item>
  </channel>
</rss>

