Reply
rob_vander2
Helper I
Helper I

Sales for the customers who bought Product A & B

Hi All,

 

I want to calculate sum of sales for those customers who bought both the Product A & B. Please see the sample data expected output in the screenshot
Screenshot 2025-03-18 at 13.40.28.png

1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

You could also try this one below. Don't know if it is better then the one using the intersect, but prefer it over using SUMX.

CALCULATE(SUM(Sales[Sales])
	,FILTER(VALUES(Sales[CustID]),AND(
		CALCULATE(COUNTROWS(Sales),Sales[Product]="A")>0
		,CALCULATE(COUNTROWS(Sales),Sales[Product]="B")>0
)))

View solution in original post

7 REPLIES 7
sjoerdvn
Super User
Super User

You could also try this one below. Don't know if it is better then the one using the intersect, but prefer it over using SUMX.

CALCULATE(SUM(Sales[Sales])
	,FILTER(VALUES(Sales[CustID]),AND(
		CALCULATE(COUNTROWS(Sales),Sales[Product]="A")>0
		,CALCULATE(COUNTROWS(Sales),Sales[Product]="B")>0
)))

This seems faster than other. Sumx is slower than all.

andrewsommer
Impactful Individual
Impactful Individual

Product A&B Sales = CALCULATE(SUM(Sales[Sales]),FILTER,ALL(Sales[Product]), Sales[Product] in {“A”,”B”))

 

Please mark this post as solution if it helps you. Appreciate Kudos.

@andrewsommer  This will not work. It's goving all customers who purchase A or B. I want customers who purchased A & B. 

rob_vander2
Helper I
Helper I

@Deku  I have got the below DAX as well
which one will be better?

VAR __custwithProductA = CALCULATETABLE(VALUES(Sales[CustID]), Sales[Product] ="A" )
VAR __custwithProductB = CALCULATETABLE(VALUES(Sales[CustID]), Sales[Product] ="B" )
VAR __CustwithProductA_B = INTERSECT(__custwithProductA,__custwithProductB)
VAR __Results = CALCULATE(SUM(Sales[Sales]), Sales[CustID] in __CustwithProductA_B)

RETURN __Results
Deku
Community Champion
Community Champion

Hard to say. Would need to run in Dax studio and look at server timings. Doubt much difference 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Deku
Community Champion
Community Champion

Sumx(

Values(table[custID]),

Var products = calculatetable( values( tables[product] )

Return 

If( "A" in product && "B" in products, table[sales])

)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)