Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Sum total time between timestamps from logging table

Hello

 

I have two tables below, one with employees and one table with transactions where they start and stop their clock. I need to sum the total of hours between the start and stop for each logging. I'm stuck and would appreciate your help 

 

There is no ID to the transaction, so I need to calculate the time between the first <Start> and the first <Stop>, then move to the second <start> against the second <stop>, and so on. There can be thousands of transactions in the real table

 

Employees  
IDEmployee Name
1Mike 
2Steve 
   
   
Timelog  
EmployeeIDActivityTimestamp
1Start2018-11-20 10:00
1Stop2018-11-20 11:00
1Start2018-11-20 14:00
1Stop2018-11-20 15:00
2Start2018-11-20 15:00
2Stop2018-11-20 16:00
   
   
End result  
EmployeeTotal time (hours)
Mike2 
Steve1 
1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

The solution of PattemManohar should be useful.

 

By  my tests, you could create a calculated column with the formula below then you could get your desired output.

 

Hour =
VAR a =
    CALCULATE (
        MAX ( 'Timelog'[Timestamp] ),
        FILTER (
            ALL ( 'Timelog' ),
            'Timelog'[Timestamp] < EARLIER ( 'Timelog'[Timestamp] )
                && 'Timelog'[EmployeeID] = EARLIER ( 'Timelog'[EmployeeID] )
                && 'Timelog'[Activity] <> EARLIER ( 'Timelog'[Activity] )
                && 'Timelog'[Activity] = "Start"
        )
    )
RETURN
    DATEDIFF ( a, 'Timelog'[Timestamp], HOUR )

Here is the output.

 

Untitled.png

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
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

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

The solution of PattemManohar should be useful.

 

By  my tests, you could create a calculated column with the formula below then you could get your desired output.

 

Hour =
VAR a =
    CALCULATE (
        MAX ( 'Timelog'[Timestamp] ),
        FILTER (
            ALL ( 'Timelog' ),
            'Timelog'[Timestamp] < EARLIER ( 'Timelog'[Timestamp] )
                && 'Timelog'[EmployeeID] = EARLIER ( 'Timelog'[EmployeeID] )
                && 'Timelog'[Activity] <> EARLIER ( 'Timelog'[Activity] )
                && 'Timelog'[Activity] = "Start"
        )
    )
RETURN
    DATEDIFF ( a, 'Timelog'[Timestamp], HOUR )

Here is the output.

 

Untitled.png

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks both of you! Got me started

PattemManohar
Community Champion
Community Champion

@Anonymous I've recently posted a solution to same scenario, please have a look if that helps and post any questions...

 

https://community.powerbi.com/t5/Desktop/calculating-working-time-in-office/m-p/567548#M267842





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors