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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ConArm89
Frequent Visitor

How to use the equivalent of the Excel Countifs statement using DAX

Hi gang,

 

Im trying to get more involved with powerBI but it frsutrates me that the things I can do incredibly fast in excel, I cant seem to get to work in DAX.

 

Maybe some of you could help?

 

I have a few tables, all built with proper relationships by case #.

 

I need to count the amount of case #'s based on certain criteria.

 

example:

 

#                   Significant Case?           Type

Case 1                   Yes                          Environmental

Case 2                   Yes                          Injury

Case 3                    No                          Other

 

so if I wanted to create a measure that counted all of the cases that are significant and of type Environmental, what would I use?

 

So far I was trying to use something similar to this:

 

Case count = CALCULATE (COUNTROWS('table1), FILTER('table1','table1'[significant case?]="Yes"), FILTER('table1','table1'[type]="Injury"))

 

Basically I need to know what the proper format is to count a row, but only count based on multiple criteria. Some of the criteria area actually in a different table. bonus points if anyone can tell me how to do a filter based on only items from this year (one of the tables has a date column I could leverage).

 

Hopefully this makes sense?

 

Any help would be amazing. Thanks!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Should just be something like:

 

Measure = COUNTROWS(FILTER('table1','table1'[significant case?]="Yes" && 'table1'[type]="Injury"))

That being said, a potentially more flexible and useful way would be to just say:

 

Measure = COUNTROWS('table1')

And then put your two columns in separate slicers and now you have a generic measure that you can use with any criteria.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @ConArm89

Addition to Greg_Deckler's suggestion, to answer your question

"if I wanted to create a measure that counted all of the cases that are significant and of type Environmental, what would I use?"

You could use the following formula

CALCULATE (COUNTROWS('table1), FILTER('table1','table1'[significant case?]="Yes"&&'table1'[Type]="Environmental")

Best regards

Maggie

Greg_Deckler
Super User
Super User

Should just be something like:

 

Measure = COUNTROWS(FILTER('table1','table1'[significant case?]="Yes" && 'table1'[type]="Injury"))

That being said, a potentially more flexible and useful way would be to just say:

 

Measure = COUNTROWS('table1')

And then put your two columns in separate slicers and now you have a generic measure that you can use with any criteria.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.