cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

How to create countifs in DAX - replicate Excel countifs

I'm trying to replicate Excel's countifs function. I've seen a couple other posts but I'm new to DAX and not totally clear how to do this.

 

How do I create a DAX formula that evaluates three separate columns and returns the count of how often the rows repeat?

 

Below I've created what I want in Excel. Column AK is what I want to create in DAX

countif dax.png

 

I tried just evaluating one column to get me started and I'm clearly doing something wrong. Here is the formula I tried:

Column = calculate(countx(Deliveries,DISTINCTCOUNT(Deliveries[Delivery])))
...but I just get a result of 1 for every row.
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Continued Contributor
Continued Contributor

Re: How to create countifs in DAX - replicate Excel countifs

Hi @jcueland 

 

use below dax, it should work

 

Countifs=
var delivery = 'Table'[Delivery]
var salesdoc = 'Table'[SalesDoc]
var item = 'Table'[Item]

RETURN

COUNTROWS(
FILTER(
all('Table'),
delivery='Table'[Delivery] &&
salesdoc=''Table'[SalesDoc] &&
item='Table'[Item]))

 

 

 

Please change the table name as per your table name, please let me know if this works for you.

View solution in original post

5 REPLIES 5
Highlighted
Super User II
Super User II

Re: How to create countifs in DAX - replicate Excel countifs

what are you trying to evaluate exactly, if you can say what you trying to do, then i can help, but i think what you might be needing is the filter() function.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Continued Contributor
Continued Contributor

Re: How to create countifs in DAX - replicate Excel countifs

Hi @jcueland 

 

use below dax, it should work

 

Countifs=
var delivery = 'Table'[Delivery]
var salesdoc = 'Table'[SalesDoc]
var item = 'Table'[Item]

RETURN

COUNTROWS(
FILTER(
all('Table'),
delivery='Table'[Delivery] &&
salesdoc=''Table'[SalesDoc] &&
item='Table'[Item]))

 

 

 

Please change the table name as per your table name, please let me know if this works for you.

View solution in original post

Highlighted
Helper V
Helper V

Re: How to create countifs in DAX - replicate Excel countifs

My data has double counts in it for some columns but not others.

 

For the columns that have double counts I want to adjust the values (by creating a new column) to reflect the double counting. E.g., there are delivery expenses that show up multiple times. The delivery expense in total is $10...but the row is repeated three times so when it's summed together it's $30. I want to add another column that divides by how often there is double counting. So, to continue the example the # of double counts might be 3 so I take $30 / 3 = $10 so I can sum correctly.

Highlighted
Helper V
Helper V

Re: How to create countifs in DAX - replicate Excel countifs

It worked! I had to change "item" to "item1" because I got a red error line, but now it worked.

 

Can you tell me how this is working so I can learn please?

Highlighted
Continued Contributor
Continued Contributor

Re: How to create countifs in DAX - replicate Excel countifs

Hi @jcueland 

Very glad it worked for you, in order to answer your question.

 

Basically it's similar logic of countifs in excel.

 

We are filtering all three columns with 'AND' operator as per the criteria at row level and then counting the rows. Hope this helps, feel free to ask more questions.

 

Thanks

https://www.linkedin.com/in/manawar-hossain-a7475614/ 

Helpful resources

Announcements
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Don't miss the Power BI Dev Camp this week!

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors