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
ExcelBot0815
Regular Visitor

DAX: Calculating the number of rows with a condition

Hello everyone,

 

I am pretty new to PowerBI and have a question.

I want to do something rather simple but I am lacking the syntax to do it. I constantly produce errors or wrong results, which is why I am trying my luck on here.

 

A simplified version of what I want to do is this:

Unbenannt.PNG

 

I have column A and B in my data set and I want to calculate column C and D in the data model:

  • In column C I want to count the number of rows that a certain product (column A) has within the given category (column B)
  • Then in column D I want to rank the products by number of rows per category.

 

I know that I have to use "calculate" and "countrows" and "filter" and "rank" but I just can't figure out how to solve this. Please note that I can't use absolute values for neither product nor category, because I have 539 distinct products in 259 distinct categories.

 

Any input is very much appreciated.

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Try out these two columns:

 

Count = 
VAR __table = FILTER(ALL('Table7'),[A] = EARLIER([A]) && [B] = EARLIER([B]))
RETURN
COUNTX(__table,[B])

Rank = RANKX(FILTER(ALL('Table7'),[B] = EARLIER([B])),[Count],,DESC,Dense)

See Table7 of attached.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Try out these two columns:

 

Count = 
VAR __table = FILTER(ALL('Table7'),[A] = EARLIER([A]) && [B] = EARLIER([B]))
RETURN
COUNTX(__table,[B])

Rank = RANKX(FILTER(ALL('Table7'),[B] = EARLIER([B])),[Count],,DESC,Dense)

See Table7 of attached.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Works as intended. Thank you very much.

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.