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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rks
Resolver I
Resolver I

dax.do // Find products bought by same customers

Hi Community,

 

I have a little DAX-problem:

 

EVALUATE
CALCULATETABLE (
SUMMARIZE (Sales, Sales[ProductKey], Sales[CustomerKey]),
Customer[CustomerKey] IN { 17447, 17419 }
)

This table on https://dax.do/W8SMqM1rHrnGbL/ shows that the Product 1715 was bought by exactly two customers. Both customers also bought different products. I want to find all products that were bought by these two customers together, so only 1715 from that list.

 

EVALUATE
CALCULATETABLE (
VALUES(Sales[ProductKey]),
Customer[CustomerKey] IN { 17447, 17419 }
)

This formula gives me an "OR" condition and finds all product bought by either customer 17447 OR 17419. But I want to find - like I said, all products by customer 17447 AND customer 17419.

 

Thank you guys!

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1662649765032.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!

View solution in original post

7 REPLIES 7
rks
Resolver I
Resolver I

@tamerj1 exactly, the two customers are actually coming from a slicer and are arbitrary. Could be also 3 or 4. But @CNENFRNL 's answer would provide the desired result, if the 2 would be replaced by "COUNTROWS(Customer)"

@rks 
Indeed, @CNENFRNL's solution is brilliant!

johnt75
Super User
Super User

EVALUATE
VAR cust17447 =
    CALCULATETABLE (
        VALUES ( Sales[ProductKey] ),
        TREATAS ( { 17447 }, Customer[CustomerKey] )
    )
VAR cust17419 =
    CALCULATETABLE (
        VALUES ( Sales[ProductKey] ),
        TREATAS ( { 17419 }, Customer[CustomerKey] )
    )
RETURN
    INTERSECT ( cust17447, cust17419 )
rks
Resolver I
Resolver I

@tamerj1 
What I want is a table containing this product,because it was the only product bought by the  2 customers in the filter.

rks_0-1662647543231.png

 

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1662649765032.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!

@rks 

For 2 products its easy

EVALUATE
INTERSECT (
    CALCULATETABLE ( VALUES ( Sales[ProductKey] ), Customer[CustomerKey] = 17419 ),
    CALCULATETABLE ( VALUES ( Sales[ProductKey] ), Customer[CustomerKey] = 17447 )
)

 but to do that dynamically regardless of the whatever customers are selected and whatever number ofcustomers then it's another story   

tamerj1
Super User
Super User

@rks 

I guess you wat to do that for any selected number of customers, could be 3 or more?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors