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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register 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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.