<?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: combinatorics in dinamic dax in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617350#M176711</link>
    <description>&lt;P&gt;Hey there! thankyou for your return;&lt;/P&gt;&lt;P&gt;This code you provided is generating an error: The &lt;STRONG&gt;GENERATE&lt;/STRONG&gt; function does not allow two columns with the same name &lt;STRONG&gt;"DB_ORDERS"[Cliente]&lt;/STRONG&gt;. i got this same problem in other attempts..&lt;/P&gt;</description>
    <pubDate>Thu, 20 Mar 2025 00:37:16 GMT</pubDate>
    <dc:creator>ClaudioF</dc:creator>
    <dc:date>2025-03-20T00:37:16Z</dc:date>
    <item>
      <title>combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617121#M176690</link>
      <description>&lt;P&gt;Hello guys, i have posted here so many times about getting a logic right, but i just noticed it was impossible, in the way i was thinking, no one could help me.&lt;/P&gt;&lt;P&gt;I have a new aproach of how to get the desired result, its by using combinatorics, of course, i need to know if its even possible in the dax.&lt;/P&gt;&lt;P&gt;I have the image bellow that shows how the combinations might work, and ahead i also have the code i'm trying, its not working properly and i would like some help with it.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this code, the objective is have at the end the combinations that attend to the condition that the amount of concatenated orders is the highest and the sum of values are &lt;STRONG&gt;&amp;lt;= 21.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Obs.&lt;/STRONG&gt; this code might work with many different products, but to this example i just used one.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FinalCorrectStatus =&lt;BR /&gt;VAR CurrentItem = SELECTEDVALUE('DB_ORDERS'[Produto])&lt;BR /&gt;VAR OrdersTable = FILTER(ALL('DB_ORDERS'), 'DB_ORDERS'[Produto] = CurrentItem)&lt;/P&gt;&lt;P&gt;VAR OrderCombinations =&lt;BR /&gt;ADDCOLUMNS(&lt;BR /&gt;GENERATEALL(&lt;BR /&gt;OrdersTable,&lt;BR /&gt;SUMMARIZE(&lt;BR /&gt;OrdersTable,&lt;BR /&gt;'DB_ORDERS'[Pedido],&lt;BR /&gt;"Soma_Quant_Falta", SUM('DB_ORDERS'[QT. falt])&lt;BR /&gt;)&lt;BR /&gt;),&lt;BR /&gt;"PedidosConcatenados", CONCATENATEX(OrdersTable, 'DB_ORDERS'[Pedido], ", "),&lt;BR /&gt;"Qtd_Pedidos", COUNTROWS(OrdersTable) -- Conta o número de pedidos na combinação&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;VAR FilteredCombinations =&lt;BR /&gt;FILTER(OrderCombinations, [Soma_Quant_Falta] &amp;lt;= 21)&lt;/P&gt;&lt;P&gt;VAR MaxPedidos = MAXX(FilteredCombinations, [Qtd_Pedidos]) -- Encontra o maior número de pedidos&lt;/P&gt;&lt;P&gt;VAR BestCombination =&lt;BR /&gt;FILTER(FilteredCombinations, [Qtd_Pedidos] = MaxPedidos) -- Mantém apenas a combinação com mais pedidos&lt;/P&gt;&lt;P&gt;RETURN BestCombination&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me with it?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 18:54:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617121#M176690</guid>
      <dc:creator>ClaudioF</dc:creator>
      <dc:date>2025-03-19T18:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617344#M176710</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="911636" data-lia-user-login="ClaudioF" class="lia-mention lia-mention-user"&gt;ClaudioF&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;BestCombination =
VAR CurrentProduct = SELECTEDVALUE('DB_ORDERS'[Produto])

VAR OrdersTable =
    FILTER(
        ALL('DB_ORDERS'),
        'DB_ORDERS'[Produto] = CurrentProduct
    )

VAR AllCombos =
    GENERATE(
        OrdersTable,
        FILTER(
            OrdersTable,
            'DB_ORDERS'[Pedido] &amp;lt;= EARLIER('DB_ORDERS'[Pedido])
        )
    )

VAR CombosWithSum =
    ADDCOLUMNS(
        AllCombos,
        "PedidosConcatenados", CONCATENATEX(
            FILTER(
                OrdersTable,
                'DB_ORDERS'[Pedido] &amp;lt;= EARLIER('DB_ORDERS'[Pedido])
            ),
            'DB_ORDERS'[Pedido],
            ", ",
            'DB_ORDERS'[Pedido], ASC
        ),
        "Soma_Quant_Falta", SUMX(
            FILTER(
                OrdersTable,
                'DB_ORDERS'[Pedido] &amp;lt;= EARLIER('DB_ORDERS'[Pedido])
            ),
            'DB_ORDERS'[QT. falt]
        ),
        "Qtd_Pedidos", COUNTROWS(
            FILTER(
                OrdersTable,
                'DB_ORDERS'[Pedido] &amp;lt;= EARLIER('DB_ORDERS'[Pedido])
            )
        )
    )

VAR FilteredCombos =
    FILTER(
        CombosWithSum,
        [Soma_Quant_Falta] &amp;lt;= 21
    )

VAR MaxQtdPedidos =
    MAXX(FilteredCombos, [Qtd_Pedidos])

VAR BestComboFinal =
    TOPN(
        1,
        FILTER(FilteredCombos, [Qtd_Pedidos] = MaxQtdPedidos),
        [Soma_Quant_Falta], DESC
    )

RETURN
    CONCATENATEX(
        BestComboFinal,
        [PedidosConcatenados],
        "; "
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generate combinations by comparing each order to orders with equal or lower numbers to simplify calculations.&lt;BR /&gt;Calculate the sum (Soma_Quant_Falta) and count (Qtd_Pedidos) for each combination.&lt;BR /&gt;Filter only combinations whose sum is &amp;lt;= 21.&lt;BR /&gt;Pick the combination with the maximum number of orders (Qtd_Pedidos).&lt;BR /&gt;Finally, concatenate the order numbers clearly for display.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If this post&lt;STRONG&gt; helps&lt;/STRONG&gt;, please consider &lt;STRONG&gt;accepting&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;it as the solution&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Appreciate your Kudos!!&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.linkedin.com/in/vahid-dm/" target="_blank" rel="noopener noreferrer"&gt;LinkedIn&lt;/A&gt;|&lt;A href="https://twitter.com/VahidDMcom" target="_blank" rel="noopener noreferrer"&gt;Twitter&lt;/A&gt;|&lt;A href="https://www.vahiddm.com/" target="_blank" rel="noopener noreferrer"&gt;Blog&amp;nbsp;&lt;/A&gt;|&lt;A href="https://www.youtube.com/@databis" target="_blank" rel="noopener noreferrer"&gt;YouTube&lt;/A&gt;&lt;A href="https://www.youtube.com/@databis" target="_blank" rel="noopener noreferrer"&gt;&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 00:20:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617344#M176710</guid>
      <dc:creator>VahidDM</dc:creator>
      <dc:date>2025-03-20T00:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617350#M176711</link>
      <description>&lt;P&gt;Hey there! thankyou for your return;&lt;/P&gt;&lt;P&gt;This code you provided is generating an error: The &lt;STRONG&gt;GENERATE&lt;/STRONG&gt; function does not allow two columns with the same name &lt;STRONG&gt;"DB_ORDERS"[Cliente]&lt;/STRONG&gt;. i got this same problem in other attempts..&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 00:37:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617350#M176711</guid>
      <dc:creator>ClaudioF</dc:creator>
      <dc:date>2025-03-20T00:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617466#M176715</link>
      <description>&lt;P&gt;You right &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;Try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;BestCombination =
VAR CurrentProduct = SELECTEDVALUE('DB_ORDERS'[Produto])

VAR OrdersTable =
    FILTER(
        ALL('DB_ORDERS'),
        'DB_ORDERS'[Produto] = CurrentProduct
    )

VAR OrdersDistinct =
    SELECTCOLUMNS(
        OrdersTable,
        "Pedido", 'DB_ORDERS'[Pedido],
        "QT_falt", 'DB_ORDERS'[QT. falt]
    )

VAR Combos =
    GENERATE(
        OrdersDistinct,
        FILTER(
            OrdersDistinct,
            [Pedido] &amp;lt;= EARLIER([Pedido])
        )
    )

VAR ComboSummary =
    ADDCOLUMNS(
        Combos,
        "PedidosConcatenados",
            CONCATENATEX(
                FILTER(OrdersDistinct, [Pedido] &amp;lt;= EARLIER([Pedido])),
                [Pedido],
                ", ",
                [Pedido], ASC
            ),
        "Soma_Quant_Falta",
            SUMX(
                FILTER(OrdersDistinct, [Pedido] &amp;lt;= EARLIER([Pedido])),
                [QT_falt]
            ),
        "Qtd_Pedidos",
            COUNTROWS(
                FILTER(OrdersDistinct, [Pedido] &amp;lt;= EARLIER([Pedido]))
            )
    )

VAR FilteredCombos =
    FILTER(
        ComboSummary,
        [Soma_Quant_Falta] &amp;lt;= 21
    )

VAR MaxQtdPedidos =
    MAXX(FilteredCombos, [Qtd_Pedidos])

VAR BestCombo =
    TOPN(
        1,
        FILTER(FilteredCombos, [Qtd_Pedidos] = MaxQtdPedidos),
        [Soma_Quant_Falta], DESC
    )

RETURN
    CONCATENATEX(
        BestCombo,
        [PedidosConcatenados],
        "; "
    )
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Mar 2025 04:00:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4617466#M176715</guid>
      <dc:creator>VahidDM</dc:creator>
      <dc:date>2025-03-20T04:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4620156#M176823</link>
      <description>&lt;P&gt;didnt work.. i think its not even possible though, i am thinking about changing to python completlty in order to achieve this result i need&lt;/P&gt;</description>
      <pubDate>Fri, 21 Mar 2025 16:10:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4620156#M176823</guid>
      <dc:creator>ClaudioF</dc:creator>
      <dc:date>2025-03-21T16:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: combinatorics in dinamic dax</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4684624#M179420</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="911636" data-lia-user-login="ClaudioF" class="lia-mention lia-mention-user"&gt;ClaudioF&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to Microsoft Fabric Community. Sorry for the delay in response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="315278" data-lia-user-login="VahidDM" class="lia-mention lia-mention-user"&gt;VahidDM&lt;/a&gt;&amp;nbsp; for the prompt response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 11:28:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/combinatorics-in-dinamic-dax/m-p/4684624#M179420</guid>
      <dc:creator>v-sathmakuri</dc:creator>
      <dc:date>2025-05-08T11:28:34Z</dc:date>
    </item>
  </channel>
</rss>

