<?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: Create custom folding function for STRING_AGG in PostgreSQL in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288910#M58313</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/608865"&gt;@DataNinja777&lt;/a&gt;&amp;nbsp;, thank you for your quick reply.&lt;/P&gt;&lt;P&gt;However, as I have only read access to the database (and admins made me understand that no changes were possible), I can't process as you propose.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, be able to create custom folding logic between PowerQuery and SQL might even more accelerate data exploration in PowerBI, and thus be useful to a wide range of users.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2024 12:57:27 GMT</pubDate>
    <dc:creator>Alex_RM</dc:creator>
    <dc:date>2024-11-18T12:57:27Z</dc:date>
    <item>
      <title>Create custom folding function for STRING_AGG in PostgreSQL</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288501#M58307</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working for a while with a PostgreSQL database.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query folding works well on most of the Power Query steps I added (such as adding simple columns, filter rows, and so on), but one very important function to me isn't folded: STRING_AGG, see&amp;nbsp;&lt;A href="https://neon.tech/postgresql/postgresql-aggregate-functions/postgresql-string_agg-function" target="_self"&gt;PostgreSQL STRING_AGG() Function By Practical Examples (neon.tech)&lt;/A&gt;. It's an aggregation function working along with GROUP BY statement (the same way as SUM for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The equivalent of STRING_AGG in Power Query would be Text.Combine, but this function appears not to be foldable. Groupping a table with a numeric aggregation function (List.Sum, List.Count, ...) is foldable, while a text aggregation with Text.Combine isn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this PowerQuery statement is folded:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Table.Group(previousStep, {"KeyColumn"}, {{"AggColumn", each List.Sum([IntColumn]), type number}})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while this one isn't:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Table.Group(previousStep, {"KeyColumn"}, {{"AggColumn", each Text.Combine([TextColumn], ", "), 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;So, is it possible to add a custom translator PowerQuery -&amp;gt; SQL for the Text.Combine function, which will be automatically called each time the PowerQuery folding engine reads a Text.Combine function? Or, do you know if there is a foldable workaround to avoid usage of Text.Combine while achieving the same behavior?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read some posts about the Value.NativeQuery function, but it's not convenient at all, since I need to manually write the SQL statement.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 09:47:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288501#M58307</guid>
      <dc:creator>Alex_RM</dc:creator>
      <dc:date>2024-11-18T09:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom folding function for STRING_AGG in PostgreSQL</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288819#M58311</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/851012"&gt;@Alex_RM&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;One way to approach your issue is to create a SQL view in your PostgreSQL database that uses the STRING_AGG function and then connect Power Query to the view.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Define the view in your database:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;sql&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CREATE VIEW AggregatedData AS
SELECT KeyColumn, STRING_AGG(TextColumn, ', ') AS AggColumn
FROM your_table
GROUP BY KeyColumn;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;In Power Query, connect to the view:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = PostgreSQL.Database("your_connection_string"),
    AggregatedData = Source{[Schema="public", Item="AggregatedData"]}[Data]
in
    AggregatedData
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Simplifies the Power Query logic.&lt;/LI&gt;
&lt;LI&gt;Folding is fully supported because the heavy lifting is done in SQL.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 12:02:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288819#M58311</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2024-11-18T12:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom folding function for STRING_AGG in PostgreSQL</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288910#M58313</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/608865"&gt;@DataNinja777&lt;/a&gt;&amp;nbsp;, thank you for your quick reply.&lt;/P&gt;&lt;P&gt;However, as I have only read access to the database (and admins made me understand that no changes were possible), I can't process as you propose.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, be able to create custom folding logic between PowerQuery and SQL might even more accelerate data exploration in PowerBI, and thus be useful to a wide range of users.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 12:57:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4288910#M58313</guid>
      <dc:creator>Alex_RM</dc:creator>
      <dc:date>2024-11-18T12:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom folding function for STRING_AGG in PostgreSQL</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4290366#M58334</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/851012"&gt;@Alex_RM&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;There are two suggested methods to address this issue:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Write the SQL Query in Power Query&lt;/STRONG&gt;: Use&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;Value.NativeQuery&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to directly write the SQL query that includes the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;STRING_AGG&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;function. This ensures that the aggregation is performed on the SQL Server side, maintaining query folding.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Sql.Database("Servername", "Database name"),
    Query = "
        SELECT KeyColumn, STRING_AGG(TextColumn, ', ') AS AggColumn
        FROM YourTable
        GROUP BY KeyColumn
    ",
    Result = Value.NativeQuery(Source, Query)
in
    Result&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;2. Use DAX's CONCATENATEX Function&lt;/STRONG&gt;&lt;SPAN&gt;: Perform the aggregation using DAX in Power BI. This method involves creating a new calculated column or measure using the&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;CONCATENATEX&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;function to achieve the same result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://radacad.com/concatenatex-in-power-bi-and-dax-concatenate-values-of-a-column" target="_blank"&gt;ConcatenateX in Power BI and DAX: Concatenate Values of a Column - RADACAD&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_1-1731998648159.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1201953i48A91B2DCCA07BF2/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_1-1731998648159.png" alt="vyiruanmsft_1-1731998648159.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 06:44:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4290366#M58334</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-19T06:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom folding function for STRING_AGG in PostgreSQL</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4290652#M58343</link>
      <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;, thank you for your message. I will likely go with the 2nd solution, even if it's not the most performance-friendly practice (since it requires to load the full related table in the data model, which is pretty large in my case).&lt;/P&gt;&lt;P&gt;But it will indeed do the job. Accepted as solution!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 08:46:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-custom-folding-function-for-STRING-AGG-in-PostgreSQL/m-p/4290652#M58343</guid>
      <dc:creator>Alex_RM</dc:creator>
      <dc:date>2024-11-19T08:46:43Z</dc:date>
    </item>
  </channel>
</rss>

