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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Amanda_Araujo
Frequent Visitor

A ranking for the top products sold together

Hello!

 

I have a basket market problem to solve. First, I did my basket market analysis by using this video from Enterprise DNA and it work really well. Then, I found a measure here  in PBI Community, to found the top combinations of products and it works too, but I can't use this measure to create a chart.

 

So what I need is: a ranking of the most sold together product that I can use to create a chart and a table.

 

All the codes that worked for me is down below:

 

THE BASKET ANALYSIS

Same Product Selected =
IF( SELECTEDVALUE( '@Cesta_Produtos'[ID] ) <> SELECTEDVALUE( WooCommerce[ID Produto] ),
 BLANK(),
  TRUE)
 
Customers Who Bought =
IF([Same Product Selected],
    BLANK(),
    DISTINCTCOUNT(WooCommerce[CPF ANONIMO NEW]))
 
Customers w/ both =
VAR MultiPurchaseEvaluation =
    CALCULATETABLE(VALUES(WooCommerce[CPF ANONIMO NEW]),
    ALL ('SKUs (2)'),
    USERELATIONSHIP(WooCommerce[ID Produto], '@Cesta_Produtos'[ID]))

RETURN
IF ([Same Product Selected] = TRUE,
    BLANK(),
        CALCULATE([Customers Who Bought], MultiPurchaseEvaluation))
 
TOP 10 COMBINATIONS
 
Highest Combo =
VAR cj1 =
    DISTINCT ( SELECTCOLUMNS (WooCommerce, "Product1", WooCommerce[Nome Curso]))
VAR cj2 =
    DISTINCT ( SELECTCOLUMNS ( WooCommerce, "Product2", WooCommerce[Nome Curso] ) )
VAR cj =
    FILTER ( CROSSJOIN ( cj1, cj2 ), [Product1] <> [Product2] )
VAR summary =
    ADDCOLUMNS (
        cj,
        "@total",
            VAR prod1 = [Product1]
            VAR prod2 = [Product2]
            RETURN
                COUNTROWS (
                    FILTER (
                        ALL ( WooCommerce[CPF ANONIMO NEW] ),
                        AND (
                            NOT ( ISBLANK ( CALCULATE ( COUNTROWS ( WooCommerce ), WooCommerce[Nome Curso] = prod1 ) ) ),
                            NOT ( ISBLANK ( CALCULATE ( COUNTROWS ( WooCommerce ), WooCommerce[Nome Curso] = prod2 ) ) )
                        )
                    )
                )
    )
VAR productslist =
    CONCATENATEX (
        TOPN ( 10, summary, [@total], DESC, [Product1], ASC ),
        [Product1] & " e " & [Product2] & UNICHAR(10)
    )
RETURN
    productslist
 
Thanks a lot!
0 REPLIES 0

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.