How to Calculate Appointment Durations and Year Gaps in Excel
Question details
Calculate the duration of distinct appointments and conditionally fill in blank start and end years using formulas based on matching person and position records.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user is managing a database of appointments containing distinct people and positions. They need to calculate the total duration of these appointments while dynamically filling in missing year gaps for corresponding records.
- Observed behavior
- Certain rows have blank start and end years within a valid appointment range. The user needs to populate these blanks based on the matching start and end bounds (e.g., pulling the 1800-1803 range for intermediate rows) while preserving single-year records and original data.
Ensure your dataset is organized with dedicated columns for 'Person', 'Position', 'Start Year', and 'End Year', and verify that the recorded years are formatted as numerical values rather than text.
Use MINIFS and MAXIFS to Fill Gaps and Calculate Duration
Use conditional minimum and maximum functions to identify the correct start and end bounds for each distinct appointment group, allowing you to fill in blanks dynamically before calculating the duration.
When dealing with repeated appointments that have blank year cells in between, you can group the data by 'Person' and 'Position'. By evaluating the minimum and maximum years within these groups, you can accurately fill the missing dates without overwriting your original data.
This approach requires Excel 2019 or newer, or WPS Spreadsheet, as it utilizes the MINIFS and MAXIFS functions to evaluate multiple criteria simultaneously.
Add a new helper column next to your data. Assuming Column A is 'Person', Column B is 'Position', and Column C is 'Start Year', enter the formula: =IF(ISNUMBER(C2), C2, MINIFS($C$2:$C$100, $A$2:$A$100, A2, $B$2:$B$100, B2))
Add another helper column for the End Year. Assuming Column D contains the original End Year, enter the formula: =IF(ISNUMBER(D2), D2, MAXIFS($D$2:$D$100, $A$2:$A$100, A2, $B$2:$B$100, B2))
In a final 'Duration' column, subtract the Calculated Start Year from the Calculated End Year. To make the duration inclusive of the starting year (e.g., 1800 to 1803 equals 4 years), use: =(Calculated End Year - Calculated Start Year) + 1

Use IF Formulas with Sorted Sequential Records (Legacy Versions)
If you do not have access to the MINIFS or MAXIFS functions, you can use simple IF functions combined with chronologically sorted data to fill missing years downwards.
Calculate Complex Date Ranges with WPS Spreadsheet
WPS Spreadsheet fully supports advanced mathematical and lookup functions, allowing you to easily handle blank cells, match specific appointment ranges, and calculate data durations without switching software.
- 1. Open your dataset: Launch WPS Spreadsheet and open the .xlsx or .csv file containing your appointment records.
- 2. Apply conditional formulas: Use MINIFS and MAXIFS in new helper columns to automatically populate blank cells with the correct start and end years based on the person and position criteria.
- 3. Calculate duration: Create a duration column and subtract the calculated start year from the calculated end year to find the exact length of the appointment.
- 4. Format and save: Copy your formula results and use 'Paste as Values' to finalize the data, then save your spreadsheet seamlessly.

Frequently Asked Questions
How do I calculate duration for a single-year appointment?
For single-year appointments (where the start and end year are the same, such as 1800-1800), simple subtraction yields 0. To accurately reflect this as a 1-year duration, add 1 to your formula: = (End Year - Start Year) + 1.
Why do my formulas return a #VALUE! error when calculating year gaps?
A #VALUE! error typically occurs if your year entries are formatted as text rather than numbers, or if a cell contains hidden spaces. Use the VALUE() function, e.g., =VALUE(C2), to convert text years into calculable numbers before running your formulas.
Can I calculate the gap in years between two different appointments?
Yes. Ensure your data is sorted chronologically by person. In a new column, you can calculate the gap by subtracting the previous row's End Year from the current row's Start Year, for example: =C3 - D2.




