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
kattlees
Post Patron
Post Patron

Calculate difference between two times

I know there has been some other posts about this, but I think mine is a little different.

 

I have two columns

SCHTM is the time a surgery is supposed to start

SurgTime is the time it actually starts.

I need to find the difference in the two. The problem is, sometimes it starts late, sometimes it starts early. 

 

I have this in TimeDiff = DATEDIFF(patientinfo[SurgTime],patientinfo[SCHTM],MINUTE) but it gives me an error of "In DateDiff function, the start date cannot be greater than the end date"

 

Any help to calculate a positive or negative number?  Both columns appear as 7:15:00 AM or 2:15:25 PM

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @kattlees,

 

Based on my test, the formula below should work in your scenario. It will return a positive number when starts late, and return negative number when starts early. Smiley Happy

TimeDiff = 
IF (
    patientinfo[SurgTime] <= patientinfo[SCHTM],
    - DATEDIFF ( patientinfo[SurgTime], patientinfo[SCHTM], MINUTE ),
    DATEDIFF ( patientinfo[SCHTM], patientinfo[SurgTime], MINUTE )
)

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @kattlees,

 

Based on my test, the formula below should work in your scenario. It will return a positive number when starts late, and return negative number when starts early. Smiley Happy

TimeDiff = 
IF (
    patientinfo[SurgTime] <= patientinfo[SCHTM],
    - DATEDIFF ( patientinfo[SurgTime], patientinfo[SCHTM], MINUTE ),
    DATEDIFF ( patientinfo[SCHTM], patientinfo[SurgTime], MINUTE )
)

 

Regards

vanessafvg
Super User
Super User

Do an if statement @kattlees

 

if( date1 > date2, blank(), datediff statement)





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




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.