Forum Discussion

noannish's avatar
noannish
Frequent Visitor
2 years ago

DateDiff giving negative result when the next date-time is less than 24 hrs difference

This is for a calculated column.

Whenever the [exit time] is the next day, but within 24 hours of [enter time], I get a negative result for minutes.

All other aspects, except this, are working fine.

 

Minutes =
VAR _NonWorkingDays =
CALCULATE(
COUNTROWS('Calendar'),
'Calendar'[Day Type] <> "Work Day"
)
VAR _WorkTimeElapsed =
DATEDIFF(AuditLog[Enter_Time],AuditLog[Exit_Time], MINUTE) - (_NonWorkingDays* 24 * 60)
RETURN
_WorkTimeElapsed

4 Replies

  • SachinNandanwar's avatar
    SachinNandanwar
    Icon for Impactful Individual rankImpactful Individual

    I think it is because your exit time is before enter time in the 24 hour period.

    Can you post some data ?

    • noannish's avatar
      noannish
      Frequent Visitor
      MinutesEnter_TimeExit_Time
      -322/19/2024 8:47:00 AM2/20/2024 8:15:00 AM
      -1536/19/2024 11:32:00 AM6/20/2024 8:59:00 AM
      -3282/19/2024 2:18:00 PM2/20/2024 8:50:00 AM
      • SachinNandanwar's avatar
        SachinNandanwar
        Icon for Impactful Individual rankImpactful Individual

        Try something like this in the Return statement

        RETURN IF(
        _WorkTimeElapsed < 0,
        _WorkTimeElapsed + (24 * 60),
        _WorkTimeElapsed 
        )