cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bezzen Visitor
Visitor

Calculate time between clock in and clock out (no date info)

I'm trying to calculate how many Minutes there are between an employee's clock in and out time (in that order) to get total minutes worked. My formula: Minutes Worked = ABS(DATEDIFF('TA Data'[Clock In],'TA Data'[Clock Out],MINUTE)). It returns the correct minutes worked when Clock in time is in the AM and clock out is in the PM (see figure 1 below). However, there is no date information attached to these times so when clock in is in the PM and clock out is in the Am minutes worked ends up being calculated wrong (see figure 2 below). What formula do I need to use to calculate time from clock in until clock out, in that order?

Minutes worked.png

 

                                                                                                                Figure 1: shows correct working minutes

 

 

 

minutes worked wrong.pngFigure 2: shows incorrect working minutes. The highlighted example should show 595 actual working minutes (minutes between clock in and clock out time). Without date information it is counting minutes from clock out (AM) until clock in (PM) and showing 845 minutes.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
v-cherch-msft Super Contributor
Super Contributor

Re: Calculate time between clock in and clock out (no date info)

Hi @Bezzen

 

You may try to create below columns:

22.png

Hour =
IF (
    'TA Data'[Clock in] < 'TA Data'[Clock Out],
    ABS ( DATEDIFF ( 'TA Data'[Clock in], 'TA Data'[Clock Out], HOUR ) ),
    24 - HOUR ( 'TA Data'[Clock in] )
        + HOUR ( 'TA Data'[Clock Out] )
)
Minute =
VAR a =
    HOUR ( 'TA Data'[Clock Out] ) * 60
        + MINUTE ( 'TA Data'[Clock Out] )
VAR b =
    ( 24 - HOUR ( 'TA Data'[Clock in] ) )
        * 60
        - MINUTE ( 'TA Data'[Clock in] )
RETURN
    IF (
        'TA Data'[Clock in] < 'TA Data'[Clock Out],
        ABS ( DATEDIFF ( 'TA Data'[Clock in], 'TA Data'[Clock Out], MINUTE ) ),
        a + b
    ) 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Highlighted
v-cherch-msft Super Contributor
Super Contributor

Re: Calculate time between clock in and clock out (no date info)

Hi @Bezzen

 

You may try to create below columns:

22.png

Hour =
IF (
    'TA Data'[Clock in] < 'TA Data'[Clock Out],
    ABS ( DATEDIFF ( 'TA Data'[Clock in], 'TA Data'[Clock Out], HOUR ) ),
    24 - HOUR ( 'TA Data'[Clock in] )
        + HOUR ( 'TA Data'[Clock Out] )
)
Minute =
VAR a =
    HOUR ( 'TA Data'[Clock Out] ) * 60
        + MINUTE ( 'TA Data'[Clock Out] )
VAR b =
    ( 24 - HOUR ( 'TA Data'[Clock in] ) )
        * 60
        - MINUTE ( 'TA Data'[Clock in] )
RETURN
    IF (
        'TA Data'[Clock in] < 'TA Data'[Clock Out],
        ABS ( DATEDIFF ( 'TA Data'[Clock in], 'TA Data'[Clock Out], MINUTE ) ),
        a + b
    ) 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 40 members 1,037 guests
Please welcome our newest community members: