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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
andrewa521
Frequent Visitor

Trying to do Countif, with changing criteria

Hey all,

 

I have been browsing with no luck, I think I am trying to do something simple in excel, but cannot make it work.  Here is a sample data set.  Basically just trying to use DAX to do the countifs in the return column.  Then copy it down so my new column has the specific associated value for each row as shown below. 

 

The count if for, D2, in this case would be: =COUNTIFS($C$2:$C$9,">0",$B$2:$B$9,B2)

ClassDateValueReturn
B31-Jan31
C31-Jan00
D28-Mar42
A28-Mar31
R31-Jan00
A28-Feb22
C28-Feb21
B31-Jan00

 

 

Thanks so much

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

Column = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Date]=EARLIER(Data[Date])&&Data[Value]>0))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

Column = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Date]=EARLIER(Data[Date])&&Data[Value]>0))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you so much!  

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @andrewa521 ,

 

I made a sample and then the formula returns the result as follows.

vstephenmsft_0-1670898326779.png

You will find that the formula result is different from the returned result you provided, and I will first give the metric written in DAX according to the result returned by the formula.

Measure = COUNTROWS(FILTER(ALLSELECTED('Table'),[Date]=MAX('Table'[Date])&&[Value]>0))

vstephenmsft_1-1670898554756.png

If you want to follow your return value based on your sample data provided, you can rewrite the following measure.

Measure 2 = var _count=COUNTROWS(FILTER(ALLSELECTED('Table'),[Date]=MAX('Table'[Date])&&[Value]>0))
return IF(MAX('Table'[Value])=0,0,_count)

vstephenmsft_2-1670898665496.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors