Hi Sarah,
This may not be the most elegant approach, but...
Please see attachment.
What you asked for is a bit beyond just a formula. Also, you mentioned "hundreds of employees", if that is beyond 250 (Excel 2003 column limitation), then you'll need to do this in batches.
I primarily used Pivot tables and the WEEKNUM function (from the Analysis Toolpack) to get a result.
Sheet1 - your data (starting point)
Sheet2 - Pivot table to consolidate the info so that we get one row per day with one Employee per column. Table contains a sum of all activity hours. Also added a calculated field for ContractDailyOvertime:
=MAX(ACTIVITY_HOURS-10,0)
Sheet3 - Pivot table (copy from Sheet2) changed to display the sum of the ContractDailyOvertime.
Sheet4 - Copy of Sheet3 (removed Pivot functionality), and added a column for YearWeek:
Also built a summary table to collect the weekly sum of ContractDailyOvertime. I used a SUMIF function for this:
=SUMIF($A$5:$A$24,$A31,C$5:C$24)
Sheet5 - Identical to Sheet4 except it uses Sheet2 data, and sums the difference of the ActivityHours versus a 40 hour week to see the weekly overtime as per contract.
Sheet6 - Summary table comparison between Sheet4 and Sheet5. My assumption as to how you calculate overall overtime (daily vs weekly) as per the contract.
Sheet7 - Another Pivot table to sum the overtime originally paid.
Sheet8 - Original overtime summed by the week.
Sheet9 - Overtime paid but not according to contract.
Cheers,
Bookmarks