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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
akwang
Advocate II
Advocate II

Countif DAX

Hi I have a table with a column for order status which could either be "on time" or "delayed". I want to create a MEASURE for Total Orders delayed that will tell me how much orders were delayed. In excel i would just use the CountIF Function, but DAX doesnt have this.  Can anyone advise on how i can get this?delay.png

1 ACCEPTED SOLUTION
KHorseman
Community Champion
Community Champion

CALCULATE and FILTER are the first two things you need to learn about DAX.

 

Measure = CALCULATE(
	COUNT(TableName[Column That Identifies Unique Orders]),
	FILTER(
		TableName,
		TableName[Delay Status] = "On Time" ||
		TableName[Delay Status] = "Delayed"
	)
)




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

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi i have a Date set where can see 4 column of Ans1,ans2,ans3,ans4
i want to know in each column how many time 3 have got

if i would try same in excel so will do countif(seletshell,3)

Thanks in advance


@akwang wrote:

Hi I have a table with a column for order status which could either be "on time" or "delayed". I want to create a MEASURE for Total Orders delayed that will tell me how much orders were delayed. In excel i would just use the CountIF Function, but DAX doesnt have this.  Can anyone advise on how i can get this?delay.png


 

 

Hi,

In the Query Editor, select all column other than the 4 answer columns and click on "Unpivot other columns".  Now write this measure

=CALCULATE(COUNTROWS(Data),Data[Value]<=3)

Hope this helps.


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

You need to familiarize yourself with DAX logic:

 

This will give you count of On Time orders: 

Count of On Time Orders = CALCULATE(DISTINCTCOUNT(TableName[order_id]),TableName[Delay Status] = "On Time" )

in plain english: Calculate the distinctcount of order_ids where delay status is "on time"

 

This will give you count of Fulfilled AND On Time orders

Count of Fulfilled On Time Orders = CALCULATE(DISTINCTCOUNT(TableName[order_id]),TableName[Delay Status] = "On Time", TableName[Short Ship Status] = "Fulfilled")
KHorseman
Community Champion
Community Champion

@medecareful with that shortcut syntax. It includes an implicit ALL() clause that can cause unexpected results if you don't know what you're doing with it. Can be dangerous to suggest to beginners. I prefer to always use explicit FILTER() statements to avoid this.





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

Proud to be a Super User!




KHorseman
Community Champion
Community Champion

CALCULATE and FILTER are the first two things you need to learn about DAX.

 

Measure = CALCULATE(
	COUNT(TableName[Column That Identifies Unique Orders]),
	FILTER(
		TableName,
		TableName[Delay Status] = "On Time" ||
		TableName[Delay Status] = "Delayed"
	)
)




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

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors