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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RishikeshD
New Member

How to compare time in DAX ?

I have written following DAX code to compare if vehicle has arrived on time ( set at 12 here) . I have an Inward Table wgich has Inward Time Column of Type Short Time .

 

Vehicle Arrival Window Comformity = COUNTX(inward,(inward[Inward Time]>FORMAT("12:00","Short Time")))

 

But I getting following error :-

 

Error Message:
MdxScript(Model) (14, 69) Calculation error in measure 'employeemaster'[Lifting Distance Comformity]: DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @RishikeshD 

You can try the following code:

Vehicle Arrival Window Comformity = COUNTX(inward,TIMEVALUE(inward[Inward Time])>TIMEVALUE("12:00"))

Best Regards!

Yolo Zhu

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @RishikeshD 

You can try the following code:

Vehicle Arrival Window Comformity = COUNTX(inward,TIMEVALUE(inward[Inward Time])>TIMEVALUE("12:00"))

Best Regards!

Yolo Zhu

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

ppm1
Solution Sage
Solution Sage

Please see this article. When dealing with dates/times, it is a good practice to handle them as the numbers they are behind the scenes, and only format/display your result at the end.

Calculate and Format Durations in DAX – Hoosier BI

 

Pat

Microsoft Employee
AlexisOlson
Super User
Super User

FORMAT returns text. Try using TIME or TIMEVALUE.

TIME ( 12, 0, 0 )
TIMEVALUE ( "12 pm" )

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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