Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SammyNed
Helper I
Helper I

Common Items

Hi guys,

 

Can someone please assist? 

 

I have a table of data, (a simplified view is below), but basically we sell products.

There are 3 columns:

Order ID (unique per order)

Item_Name (items that can be added in an order)

Item_Qty (number of item_names that can be added in an order)

SammyNed_0-1628254347746.png

 

I want to know which items are frequently bought together , can use this info to perhaps have combo deals. A sample of my outcome is shown below:

SammyNed_1-1628254378659.png

 

Please assist...

Thanks in advance

1 ACCEPTED SOLUTION

 

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

7 REPLIES 7
CNENFRNL
Community Champion
Community Champion

PBI = PQ + DAX. Make the best of PQ; a mere transformation makes it way much easier,

let
    Source = List.Distinct(SALES[Item_Name]),
    Combination = Table.FromRows(List.TransformMany(Source, each List.Skip(Source, List.PositionOf(Source, _)+1), (x,y) => {x,y}), {"Item1","Item2"})
in
    Combination

Screenshot 2021-08-06 214853.png

Screenshot 2021-08-06 215125.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL 

 

Thanks for your assistance. Your solution works...

However I currently have over 3100 items for sale in the table so unfortunatly it creates a massive table that bombs out on my laptop wants it reaches about 86million rows. 

 

I'm not too farmilar with PQ, but I was thinking perhaps we could add a conditional formula in, something like only list the items purchased over 3 times together?

Currently the Sales Table just contains a list of items bought by date, so we could summarize the Sales table by count of unique items and then apply a filter for only items bought more than 3 times and then apply your suggestion above?

 

Would that be possible?

 

Thanks in advance

 

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Greg_Deckler
Community Champion
Community Champion

@SammyNed Here is a cleaned up version:

Table 2 = 
    VAR __Table = 
        DISTINCT(
            FILTER(
                GENERATE(
                    SELECTCOLUMNS(DISTINCT('Table'[Item_Name]),"Item_Name_1",[Item_Name]),
                    SELECTCOLUMNS(DISTINCT('Table'[Item_Name]),"Item_Name_2",[Item_Name])
                ),
                [Item_Name_1]<>[Item_Name_2])
            )
    VAR __Table2 = 
        ADDCOLUMNS(
            __Table,
            "__var",
            VAR __t1 = SUMMARIZE(FILTER('Table',[Item_Name] = [Item_Name_1] || [Item_Name] = [Item_Name_2]),[Order_ID],"__Count",COUNTROWS('Table'))
            RETURN
            COUNTROWS(FILTER(__t1,[__Count]>1))+0
        )
RETURN
    __Table2


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

Thanks foryour assistance.

However i currently have over 3100 items in the table and my laptop bombs out as 3100 factorial is undefined. 

 

Jihwan_Kim
Super User
Super User

Picture1.png

 

Orders Count Basket : =
VAR _itemoneorders =
VALUES ( Sales[Order_ID] )
VAR _itemtwoorders =
CALCULATETABLE (
VALUES ( Sales[Order_ID] ),
ALL ( 'Item One' ),
TREATAS ( VALUES ( 'Item Two'[Item_Name_2] ), Sales[Item_Name] )
)
VAR _newtable =
INTERSECT ( _itemoneorders, _itemtwoorders )
RETURN
IF (
HASONEVALUE ( 'Item One'[Item_Name_1] )
&& HASONEVALUE ( 'Item Two'[Item_Name_2] ),
IF (
SELECTEDVALUE ( 'Item One'[Item_Name_1] )
<> SELECTEDVALUE ( 'Item Two'[Item_Name_2] ),
COUNTROWS ( _newtable )
)
)
 
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Greg_Deckler
Community Champion
Community Champion

@SammyNed Here is one method:

 

Table 2 = 
    VAR __Table = GENERATE(SELECTCOLUMNS(DISTINCT('Table2'[Item_Name]),"Item_Name_1",[Item_Name]),SELECTCOLUMNS(DISTINCT('Table2'[Item_Name]),"Item_Name_2",[Item_Name]))
    VAR __Table1 = SELECTCOLUMNS(SUMMARIZE('Table2','Table2'[Order_ID],"__Items",CONCATENATEX('Table2',[Item_Name],",")),"__Items",[__Items])
    VAR __Table2 = 
        ADDCOLUMNS(
            __Table,
            "__var",
            VAR __t1 = SUMMARIZE(FILTER('Table2',[Item_Name] = [Item_Name_1] || [Item_Name] = [Item_Name_2]),[Order_ID],"__Count",COUNTROWS('Table2'))
            RETURN
            COUNTROWS(FILTER(__t1,[__Count]>1))
        )
RETURN
    __Table2

 

In this example, 'Table2' is the source data table you presented.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.