Managing manufacturing efficiency is highly challenging, especially when trying to isolate and analyze night shift machine downtime across complex, multi-day spreadsheets. While standard operational funding sources budget for routine maintenance, optimizing active production requires precise data. Mastering the right Excel formula grants facilities managers the exact clarity needed to pinpoint costly nocturnal bottlenecks.
Under the stipulation that night shifts cross calendar days (typically 10 PM to 6 AM), standard averaging fails. Industrial leaders like Toyota rely on advanced conditional time-tracking. Below, we break down the exact AVERAGEIFS and MOD formulas to isolate these specific hours and calculate your average downtime accurately.
In manufacturing and production environments, tracking machine downtime is critical for optimizing Overall Equipment Effectiveness (OEE), scheduling preventive maintenance, and refining operational workflows. However, analyzing downtime data for night shifts presents a unique challenge in Microsoft Excel.
Because night shifts typically cross the midnight threshold (for example, starting at 10:00 PM on Monday and ending at 6:00 AM on Tuesday), standard Excel formulas can easily return errors or incorrect averages. This happens because Excel treats dates and times as continuous serial numbers, where midnight represents a transition to a completely new calendar day.
In this comprehensive guide, we will walk through the exact Excel formulas and logical structures required to accurately isolate and average machine downtime during night shifts.
Excel stores times as fractional parts of a 24-hour day. For example, 12:00 PM (noon) is stored as 0.5, and 12:00 AM (midnight) begins a new integer day value.
When you try to run a standard formula like AVERAGEIFS with a time condition, you might naturally write a condition looking for times between 10:00 PM (22:00) and 6:00 AM (06:00). However, because 22:00 is numerically greater than 06:00, Excel's logical AND structure fails. A single timestamp cannot be both greater than or equal to 22:00 and less than or equal to 06:00 on the same calendar day.
To solve this, we must use alternative logical approaches: helper columns, SUMPRODUCT, or combinations of SUMIFS and COUNTIFS using OR logic. Let's explore the three most effective methods.
If you have the flexibility to modify your source data sheet, adding a helper column to flag the shift is the most reliable method. It keeps your final formulas clean and makes troubleshooting a breeze.
Suppose you have a table where Column B contains the Log Time of the downtime event, and Column C contains the Downtime Duration (Minutes).
We can use a helper column (Column D) named "Shift" to automatically flag whether an event occurred during the night shift (22:00 to 06:00).
Enter the following formula in cell D2 and drag it down:
=IF(OR(MOD(B2, 1) >= TIME(22, 0, 0), MOD(B2, 1) <= TIME(6, 0, 0)), "Night Shift", "Day Shift")
MOD(B2, 1): This extracts only the time portion from the cell, stripping away any date information. This is crucial if your timestamps look like "10/24/2023 23:15".TIME(22, 0, 0) and TIME(6, 0, 0): These define our shift boundaries (10 PM and 6 AM).OR(...): This returns TRUE if the time is either late at night (greater than or equal to 10 PM) OR early in the morning (less than or equal to 6 AM).Once your helper column is set up, averaging the downtime is incredibly straightforward using the standard AVERAGEIF function:
=AVERAGEIF(D2:D100, "Night Shift", C2:C100)
This formula scans your helper column for "Night Shift" and returns the average of the corresponding values in your downtime column.
If you cannot or do not want to add helper columns to your worksheet, you can use the powerful SUMPRODUCT function to perform the time-filtering and averaging in a single cell.
Assume your data is structured as follows:
To find the average night shift downtime, write the following formula:
=SUMPRODUCT(((MOD(B2:B20, 1) >= TIME(22, 0, 0)) + (MOD(B2:B20, 1) <= TIME(6, 0, 0))) * C2:C20) / SUMPRODUCT(--((MOD(B2:B20, 1) >= TIME(22, 0, 0)) + (MOD(B2:B20, 1) <= TIME(6, 0, 0)) > 0))
This formula simulates an average by manually calculating Total Night Shift Downtime (SUM) divided by the Total Number of Night Shift Events (COUNT).
+) as OR logic: In array mathematics, addition acts as an OR operator. The expression (MOD(B2:B20, 1) >= TIME(22,0,0)) + (MOD(B2:B20, 1) <= TIME(6,0,0)) returns a 1 if either condition is met, and a 0 if neither is met.SUMPRODUCT then adds them up.Sometimes, the downtime event itself spans across the midnight boundary. For example, a machine breaks down at 11:30 PM (23:30) on Monday and is fixed at 2:30 AM (02:30) on Tuesday.
If you subtract the start time from the end time using standard subtraction (End - Start), Excel will throw a string of hash symbols (#####) because Excel cannot display negative time values if the date isn't explicitly defined.
To calculate the exact duration of a downtime event that crosses midnight, use the MOD function:
=MOD(End_Time - Start_Time, 1)
By using divisor 1, the MOD function automatically adds 24 hours to the result if the end time is smaller than the start time, yielding the correct duration every time.
Once you have calculated the durations in a column using this formula, you can apply your AVERAGEIFS or AVERAGEIF functions based on the start time of the shift.
Let's look at a practical dataset and see how these formulas compute the average downtime.
| Downtime ID | Downtime Start Time | Downtime Duration (Mins) | Helper Column (Shift) |
|---|---|---|---|
| 1 | 10/24/2023 22:30 | 45 | Night Shift |
| 2 | 10/25/2023 03:15 | 90 | Night Shift |
| 3 | 10/25/2023 11:00 | 15 | Day Shift |
| 4 | 10/25/2023 18:45 | 30 | Day Shift |
| 5 | 10/25/2023 23:50 | 60 | Night Shift |
If we apply our Helper Column formula to this dataset, it correctly identifies events 1, 2, and 5 as Night Shift.
Running our AVERAGEIF formula on this table looks like this:
=AVERAGEIF(D2:D6, "Night Shift", C2:C6)
Calculation: (45 + 90 + 60) / 3 = 65 minutes of average downtime per night shift event.
IFERROR wrapper:
=IFERROR(AVERAGEIF(D2:D100, "Night Shift", C2:C100), 0)
>=, <=) will fail.AVERAGEIFS (with an "S") to add another filter condition:
=AVERAGEIFS(C2:C100, D2:D100, "Night Shift", E2:E100, "Unplanned") (where Column E lists the type of downtime).
Analyzing manufacturing metrics across shift changes doesn't have to be a headache. By leveraging helper columns with the MOD function, or using SUMPRODUCT to manage cross-midnight logic arrays, you can easily build robust Excel dashboards that keep your maintenance operations informed, accurate, and optimized.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.