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
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/
v-stephen-msft
Community Support
Community Support

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