Forum Discussion

Adams_Apple's avatar
Adams_Apple
Frequent Visitor
1 year ago
Solved

Another Matrix Sum Issue

Hey guys, Really could use some help on this one. Im calculating the "packing hours" of the factory line per shift and day. I have to do this by determining min and max times for each shift, which w...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Adams_Apple,

    Thank you for following up with the conversation. You are right that the issue lies in the time part of the logic "DATEDIFF ( TIME(0,0,0), data_Bins[Time Dumped], HOUR ) < 3". The intention here is to filter for times after midnight but before 3:00 AM on the next day of the night shift. However, this condition can be a bit fragile especially since DATEDIFF() with a static TIME(0,0,0) isn't reliable in all row contexts and can sometimes return blanks or unexpected values.

    Instead we can use the TIMEVALUE() function directly to filter by the time portion. Since your night shift runs from 4:00 PM to 3:00 AM the next day, you can adjust the logic to use ">= TIME(16, 0, 0) (4:00 PM) to end of day on currentDate" and "< TIME(3, 0, 0) (3:00 AM) on currentDate + 1".

    Try this:

    VAR nightStart =
    CALCULATE(
    MIN(data_Bins[DateTime Dumped]),
    data_Bins[Date Dumped] = currentDate,
    TIMEVALUE(data_Bins[DateTime Dumped]) >= TIME(16, 0, 0)
    )

    VAR nightStop =
    CALCULATE(
    MAX(data_Bins[DateTime Dumped]),
    data_Bins[Date Dumped] = currentDate + 1,
    TIMEVALUE(data_Bins[DateTime Dumped]) < TIME(3, 0, 0)
    )

    This approach compares the actual time portion of DateTime Dumped directly, which avoids the DATEDIFF ambiguity and handles filtering more reliably.

     

    Best Regards,.

    Hammad.