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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Count rows with multiple criterias

Hello everyone,

 

I'm looking for help on something that looks easy but I can't wrap my head around.

 

I have a table with 2 columns with consumer ids and the type of product they bought, as shown on the following table.

 

Consumer idType
1apple
2apple
2pear
3pear
4pear
4carrot
4apple
5carrot
6carrot

 

I'm looking for a Dax formula to quickly retrive the count of consumers who have bought both an apple & a pear, so in this case only id 2 & 4.

 

Thanks for your help

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Generic solution

CNENFRNL_0-1643713619629.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

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Generic solution

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

tex628
Community Champion
Community Champion

Try this:

Count = 
VAR Id_ = 'Table'[Consumer id]
return
IF( CALCULATE( COUNTROWS('Table') ,'Table'[Consumer id] = Id_ ,'Table'[Type] = "Apple" || 'Table'[Type] = "Pear" ) = 2 , 1 , BLANK() )

 

tex628_0-1643709051967.png

 


Connect on LinkedIn
amitchandak
Super User
Super User

@Anonymous , You can try solution by @mh2587 , But I think it should be like below if you need both


countx(filter(addcolumns(summarize(Table, Table[Consumer id]) , "_apple", countx(filter(Table, Table[Type] ="apple"),[Consumer id] )
, "_pear", countx(filter(Table, Table[Type] ="pear"),[Consumer id] ) ), not(isblank(_apple)) && not(isblank(_pear)) ),[Consumer id])

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
mh2587
Super User
Super User

=Calculate(COUNT[Consumer ID],[Type] IN {"apple","pear"})


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.