Forum Discussion

Alanoudfahad's avatar
Alanoudfahad
Frequent Visitor
5 years ago
Solved

Adjacent row formula using IF statement

Hello, I have this problem that I couldn't find a work around in PBI and was hoping I could find some help here. I have a check in/check out system and I want to calculate the total time an employee...
  • v-kkf-msft's avatar
    5 years ago

    Hi Alanoudfahad ,

    Try the following formula to create measures:

    next_in/out = 
    var next_time = 
        MINX(
            FILTER(
                ALL('Table'),
                'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
                && 'Table'[Time] > MAX('Table'[Time])
            ),
            'Table'[Time]
        )
    var next_in_out = 
        CALCULATE(
            MAX('Table'[In/out]),
            FILTER(
                ALL('Table'),
                'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
                && 'Table'[Time] = next_time
            )
        )
    return next_in_out
    Diff_time = 
    var next_time = 
        MINX(
            FILTER(
                ALL('Table'),
                'Table'[Personnel ID] = MAX('Table'[Personnel ID]) && 'Table'[Date] = MAX('Table'[Date])
                && 'Table'[Time] > MAX('Table'[Time])
            ),
            'Table'[Time]
        )
    return next_time - MAX('Table'[Time])
    TotalTime = 
    IF( 
        MAX('Table'[In/out]) = "IN" && [next_in/out] = "OUT",
        [Diff_time]
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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