<?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: Get top N items that are bought together with a specific item in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138812#M111981</link>
    <description>&lt;P&gt;Thanks a lot&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;. I'm gonna work on this and let you know the result:)&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 12:37:45 GMT</pubDate>
    <dc:creator>tdanielspbi</dc:creator>
    <dc:date>2023-03-17T12:37:45Z</dc:date>
    <item>
      <title>Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138502#M111953</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate the top N items that are frequently bought together and the total sales associated with those items using Power BI. I have already tried many different DAX formulas, but I can't seem to figure it out. Unfortunately, as I'm live connected to an SSAS, I can't create new tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data structure is as follows: I have one fact table with all my sales transactions. This table has a many-to-one relationship with the items, customers, and date table. Here's an example of my fact sales data table:&lt;/P&gt;Order Id Item Id Invoiced Quantity Sales Amount &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to achieve is a visualization that shows the top N items that are frequently bought together, along with the total sales associated with those items. So in the example above, Product A is bought with B, C and E.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have already tried several DAX formulas, including the one given in &lt;A href="https://www.daxpatterns.com/basket-analysis/" target="_new"&gt;https://www.daxpatterns.com/basket-analysis/&lt;/A&gt;. However, my data model won't allow me to use this example. I have also tried using the SUMMARIZE function to group the data by order ID and create a new table, but I'm not sure how to proceed from there.&lt;/P&gt;&lt;P&gt;I&lt;/P&gt;&lt;P&gt;would greatly appreciate any guidance on how to approach this problem in Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:37:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138502#M111953</guid>
      <dc:creator>tdanielspbi</dc:creator>
      <dc:date>2023-03-17T10:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138530#M111957</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526660" data-lia-user-login="tdanielspbi" class="lia-mention lia-mention-user"&gt;tdanielspbi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please clarfy how exactly would you visual look like? Do you want to have the topn combinations? or for each product, you want to have the topn other products that are sold along with this project?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:51:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138530#M111957</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-17T10:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138558#M111963</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;, ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the swift reply! I already have a visual on a page that shows top 10 items sold this year. However, for upselling possibilies I want to showcase items that are frequently bought together with those top selling items. Ideal would be that when you select one item from the visual showcasing top selling items, a table would be filled with other items and the associated sales.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:57:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138558#M111963</guid>
      <dc:creator>tdanielspbi</dc:creator>
      <dc:date>2023-03-17T10:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138785#M111979</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526660" data-lia-user-login="tdanielspbi" class="lia-mention lia-mention-user"&gt;tdanielspbi&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please refer to attached sample file with the proposed solution.&lt;/P&gt;
&lt;P&gt;You need to have a disconnected product table that will be used in the new table visual. Please ley me know if you need any help on this.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Sales Amount = 
VAR SelectedItems = VALUES ( 'Table'[Item ID] )
VAR RelatedItems = 
    CALCULATETABLE ( 
        VALUES ( 'Table'[Item ID] ),
        ALL ( 'Table'[Item ID] ),
        VALUES ( 'Table'[Order ID] )
    )
VAR RelatedItemsOnly = EXCEPT ( RelatedItems, SelectedItems )
VAR FilterTable = 
    FILTER ( 
        VALUES ( 'Bought With Products'[Item ID] ),
        'Bought With Products'[Item ID] IN RelatedItemsOnly
    )
RETURN
    CALCULATE ( 
        SUM ( 'Table'[Sales Amount] ),
        TREATAS ( 
            FilterTable,
            'Table'[Item ID]
        )
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Mar 2023 12:25:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138785#M111979</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-17T12:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138812#M111981</link>
      <description>&lt;P&gt;Thanks a lot&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;. I'm gonna work on this and let you know the result:)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 12:37:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3138812#M111981</guid>
      <dc:creator>tdanielspbi</dc:creator>
      <dc:date>2023-03-17T12:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3140365#M112104</link>
      <description>&lt;P&gt;&lt;A href="mailto:Hi@tamerj1," target="_blank"&gt;Hi@tamerj1,&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your effort in providing a solution, but I was hoping for something more specific. Instead of displaying all sales, I was expecting to see the total sales linked with the respective Order IDs. To illustrate this, let's consider the example of item B. If I choose Item B, the expected outcome would be the total sales of 20 for product A, instead of the overall sales of 70.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 20:48:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3140365#M112104</guid>
      <dc:creator>tdanielspbi</dc:creator>
      <dc:date>2023-03-18T20:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Get top N items that are bought together with a specific item</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3141655#M112202</link>
      <description>&lt;P&gt;I managed it to work add another statement to filter the RelatedOrders only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp; for your work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(Basket) Revenue for Items that are bought with Top Item = 

    VAR SelectedItems = VALUES ( Sales Table[Item ID] )
    VAR RelatedItems = 
        CALCULATETABLE ( 
            VALUES ( Sales Table[Item ID] ),
            ALL ( Sales Table[Item ID] ),
            VALUES ( Sales Table[Order ID] )
        )
    VAR RelatedOrders = 
        CALCULATETABLE ( 
            VALUES ( Sales Table[Order ID] ),
            ALL ( Sales Table[Order ID] ),
            VALUES ( Sales Table[Item ID] )
        )
    VAR RelatedItemsOnly = EXCEPT ( RelatedItems, SelectedItems )
    VAR FilterTable = 
        FILTER ( 
            VALUES ( 'Bought With Items'[Item ID] ),
            'Bought With Items'[Item ID] IN RelatedItemsOnly
        )
    RETURN
        CALCULATE ( 
            SUM ( Sales Table[Sales Amount] ),
            FILTER( ALL ( Sales Table ), Sales Table[Order ID] in RelatedOrders),
            TREATAS ( 
                FilterTable,
                Sales Table[Item ID]
            )
        )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 07:29:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-top-N-items-that-are-bought-together-with-a-specific-item/m-p/3141655#M112202</guid>
      <dc:creator>tdanielspbi</dc:creator>
      <dc:date>2023-03-20T07:29:26Z</dc:date>
    </item>
  </channel>
</rss>

