- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
)))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
)))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This seems faster than other. Sumx is slower than all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@andrewsommer This will not work. It's goving all customers who purchase A or B. I want customers who purchased A & B.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
