Forum Discussion

TiasHooijenga's avatar
TiasHooijenga
Frequent Visitor
4 years ago
Solved

Help calculating work hours duration based on status in and status out entries in Power Query

I've been struggling getting the correct amount of minutes/duration of employee work day. We have a system in place where employees update their status based on if they're working and where.   W...
  • mahoneypat's avatar
    4 years ago

    The simplest way to do this would be to first create a calculated column (DAX is better than M for this one), with the column expression below (gives the time in hours at the status on the current row by finding the next status update (in or out)). Replace Times with your actual table name.

     

    Time At Status =
    VAR thisemployee = Times[EmployeeID]
    VAR thistime = Times[Entry created at]
    VAR nexttime =
    CALCULATE (
    MIN ( Times[Entry created at] ),
    ALLEXCEPT ( Times, Times[EmployeeID] ),
    Times[Entry created at] > thistime
    )
    RETURN
    IF ( NOT ( ISBLANK ( nexttime ) ), ( nexttime - thistime ) * 24 )

     

     

    You can then use a simple measure to just count the "in" or "out" time to get your result.

     

    In total = CALCULATE(SUM(Times[Time At Status]), Times[Status] = "In")

     

    Pat