Calculation Issues

How to Count Employees Working Each Hour in Excel (Including Midnight Shifts)

Olivia MillerOlivia Miller Nov 11, 2026 868 views

Question details

The user needs to calculate the number of employees working during each hour of the day based on employee schedules.

How to Count Employees Working Each Hour in Excel
Product
Excel
Device & OS
not provided
Scenario
Calculating hourly staffing coverage for a business schedule, specifically handling complex shifts that cross midnight and excluding 30-minute unpaid lunch breaks.
Observed behavior
Standard time difference calculations fail when a shift crosses midnight (e.g., 22:00 to 06:00), making it difficult to aggregate active working minutes against a continuous 24-hour timeline.
Before you start

Ensure all your start and end times are formatted as proper Excel Time values (e.g., hh:mm) and not as plain text to allow formula calculations to evaluate them correctly.

Solution 1Recommended

Use Date-Time Conversion and Array Formulas to Count Staff

Convert shift times into continuous date-time values to easily calculate overlaps. By adding a day to shifts that cross midnight, you can compare the shift against a standard 24-hour timeline.

Calculating hourly coverage requires breaking the day into specific hour blocks and checking if each employee's shift overlaps with that block. The biggest challenge is handling overnight shifts, which requires a mathematical adjustment to represent the next day correctly.

1
Organize Your Data Structure

Set up your worksheet with columns for 'Employee', 'Start Time', 'End Time', and 'Lunch Break'. Verify that the time entries are valid time formats.

2
Correct Shifts that Cross Midnight

Create a new column named 'Adjusted End Time'. Enter the formula `=IF(C2<B2, C2+1, C2)` (assuming B2 is Start Time and C2 is End Time). This adds 1 day (24 hours) to any shift ending earlier than it started, converting it into a continuous timeline.

3
Setup a 24-Hour Timeline

In a separate area of your sheet, create a horizontal row containing the hours of the day (e.g., 0:00, 1:00, 2:00... up to 23:00) to represent each hour block you want to analyze.

4
Apply Counting Logic for Overlapping Hours

Use an array formula or `SUMPRODUCT` under each hour block to evaluate if the timeline hour falls within the employee's adjusted shift. A basic logic structure checks `(Start_Time <= Hour_Block) * (Adjusted_End_Time > Hour_Block)`.

5
Exclude the Unpaid Lunch Break

If you know the exact lunch break interval, subtract it from the overlap calculation. If simply totaling hours, ensure you subtract `TIME(0, 30, 0)` from the employee's total working shift duration.

Use Date-Time Conversion and Array Formulas to Count Staff
Complex Scheduling Layouts: Because employee scheduling layouts vary greatly, you may need to tailor your COUNTIFS or SUMPRODUCT ranges to match exactly how your lunch break periods (fixed vs. floating) are recorded.

Easily Calculate Staffing Levels in WPS Spreadsheet

WPS Spreadsheet offers powerful date and time functions, making it simple to manage complex employee schedules, handle midnight shifts, and accurately calculate hourly coverage.

  1. 1. Open Your Schedule Data: Launch WPS Spreadsheet and open your employee shift workbook.
  2. 2. Format Time Cells: Highlight your time columns, right-click, select 'Format Cells', and ensure the 'Time' category is applied.
  3. 3. Apply Shift Adjustments: Use the formula `=IF(End<Start, End+1, End)` to seamlessly adjust any overnight working shifts.
  4. 4. Calculate the Timeline: Utilize built-in `COUNTIFS` or `SUMPRODUCT` formulas across your hourly columns to automatically count active employees per hour.
Advanced date and time formula support100% compatible with Microsoft Excel (.xlsx) formatsFree, lightweight, and easy to navigateBuilt-in spreadsheet templates for employee scheduling
microsoft office alternative - wps office

Frequently Asked Questions

How do I handle a shift that ends the next day in an Excel formula?

When calculating time differences, a shift that ends the next day will result in a negative number. You can fix this by using the formula `=MOD(End_Time - Start_Time, 1)` or `=IF(End_Time < Start_Time, End_Time + 1, End_Time)` to correctly calculate the duration.

Can I deduct exactly 30 minutes for a lunch break in Excel?

Yes. Since Excel stores time as a fraction of a 24-hour day, you can subtract 30 minutes by using the TIME function: `- TIME(0, 30, 0)` at the end of your duration calculation.

What is the best function to count occurrences across specific time ranges?

The `COUNTIFS` function is ideal for simple overlap counting. However, for more complex conditions—like checking arrays, adjusting for next-day shifts inline, and excluding overlapping lunch intervals—the `SUMPRODUCT` function provides more flexibility.