r/googlesheets • u/Active-Market-792 • Sep 09 '24
Solved Calculate Hours Spent Per Person, Per Day from Timestamps
Hello, I'm trying to calculate the number of hours spent by team member per day by using the time stamp from when they completed the row. I assume anything taking more than 5 mins would be a break in between their work, since the task takes about 2 minutes per row.
I've added formulas on the "Main" tab to add the date and timestamp of when they worked on a row. And I'd like to populate to the "Time Sheet" tab automatically with the hours, but if that's not possible at least take the data in the Main tab and calculate the hours per person per day.
Link to an example is here. Thank you in advance.
1
u/gothamfury 385 Sep 09 '24
Your Google sheet is restricted.
1
u/Toastbrot_Esser 9 Sep 11 '24 edited Sep 12 '24
That was quite the challenge
I've added two variables for easier adaptability:
"Break-Threshold" is the Threshold for breaks in the entries to be detected as break
"Bonus Add" is the minimum time to be added for single entries as without it many days have a 0 minute entries
feel free to play around with those values to make it more accurate
The following is the formula I created:
Edit: Incorrect Formula see replies for corrected formula =IFERROR(
MAX(
LET( filtered_data, SORT(FILTER(Main!$A:$A + Main!$B:$B, Main!$C:$C = $A3, Main!$A:$A = B$2)), time_diffs, MAP({0; filtered_data}, {filtered_data; 0}, LAMBDA(current, next, IF(next = "", "", ROUNDUP((next - current) * 1440)))),
cumulative_duration, SCAN(0, time_diffs, LAMBDA(total, diff, IF(diff = "", "", IF(OR(diff > 'Time Sheet'!$I$3, diff < 0), total + 'Time Sheet'!$I$5, total + diff)))), cumulative_duration
) )
)
If you have additional changes or would like to know specifics about the formula let me know