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! Request now

Reply
Anonymous
Not applicable

If Statement with Date and Time Format

Hello, 

 

Need Help with an If statement that includes all of the following factors below. I want to calculate the following

 

If the Driver pick up (Time) is 15 mins <= to the scheduled arrival time than = "On Time" 

Power BI Column:  Driver Pick up Time (1/1/2021 9:30:24 PM ) - Schedule Arrival Time (1/1/2021 9:35:00 PM)

This should pull in "On Time"

 

If the Driver pick up time is 16 mins < than the schedule arrival time than = "Early"

Power BI Column:  Driver Pick up Time (1/1/2021 9:30:24 PM ) - Schedule Arrival Time (1/1/2021 10:35:00 PM)

This Should Pull in "Early" 

 

If the Driver pick up time is > than the scheduled arrival time than  = "Late"

Power BI Column:  Driver Pick up Time (1/1/2021 9:30:24 PM ) - Scheduled Arrival Time (1/1/2021 8:35:00 PM)

This should pull in "Late"

 

My formula for some reason only pulls in "On Time" and nothing else.

1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @Anonymous,

 

Try measure as:

Measure = 
IF(
    DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)<=15 && DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)>=0,
    "on time",
    IF(
        DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)>=16,
        "Early",
        "Late"
    )
)

Here is the output:

v-xulin-mstf_0-1620203955997.png

The pbix file is attached.

 

Best Regards,
Link

 

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
v-xulin-mstf
Community Support
Community Support

Hi @Anonymous,

 

Try measure as:

Measure = 
IF(
    DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)<=15 && DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)>=0,
    "on time",
    IF(
        DATEDIFF(MAX('Table'[Driver Pick up Time]),MAX('Table'[Schedule Arrival Time]),MINUTE)>=16,
        "Early",
        "Late"
    )
)

Here is the output:

v-xulin-mstf_0-1620203955997.png

The pbix file is attached.

 

Best Regards,
Link

 

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

Anonymous
Not applicable

This is perfect thank you!!!

amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

new column =
var _diff = datediff([Driver pick up time ],[scheduled arrival time], minute)
return
switch(true() ,
_diff <0 , "Late",
_diff <=15 , "On Time",
"Early"
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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