Formula Errors

How to Sum Values for Consecutive Dates by Code in Excel

Adam DavisAdam Davis Nov 2, 2026 868 views

Question details

The user needs to calculate the sum of values for specific codes occurring on consecutive dates, while applying filters for the year, code, and a condition where the sequential date total is greater than or equal to 3.

Product
Microsoft Excel
Device & OS
not provided
Scenario
Analyzing chronological datasets where values must be aggregated conditionally based on whether dates follow each other sequentially for a specific identifier.
Observed behavior
Standard functions like SUMIFS cannot natively group and evaluate consecutive sequence lengths, requiring complex array formulas or helper columns to achieve the correct result.
Before you start

Ensure your date column is properly formatted as Dates rather than text, and sort your entire dataset chronologically by Date to allow formulas to detect sequences accurately.

Solution 1Recommended

Use Helper Columns to Identify Consecutive Date Groups

Creating a helper column is the most reliable and transparent way to identify sequential dates for a specific code before applying the final SUMIFS formula.

By breaking the problem down into multiple columns, you avoid overly complex array formulas and make the data easier to audit or adjust in the future.

1
Sort your dataset

Select your entire data range. Go to the Data tab, click Sort, and sort first by 'Code' (A to Z) and then add a level to sort by 'Date' (Oldest to Newest).

2
Create a sequence identifier

Insert a new Helper Column. In the second row of data (e.g., C2), enter a formula like =IF(AND(A2=A1, B2=B1+1), C1, C1+1) assuming A is Code and B is Date. This assigns a unique group ID to consecutive dates.

3
Calculate group lengths

In another column, use a COUNTIF formula based on the new group ID to determine how many consecutive days exist in that specific sequence.

4
Apply final filters and sum

Use a SUMIFS function to calculate the total values, adding criteria ranges to check that the Code matches your target, the Year(Date) matches your target year, and the group length helper column is >= 3.

Use Helper Columns to Identify Consecutive Date Groups
Tip: Using the YEAR() function in a separate helper column makes filtering by year much easier when using SUMIFS.

Use WPS Spreadsheet for Advanced Data Filtering and Array Formulas

WPS Spreadsheet fully supports complex array formulas, dynamic functions, and multi-condition filtering like SUMIFS. You can easily calculate consecutive date sequences and sum values with strict criteria for free.

  1. 1. Open data in WPS: Launch WPS Spreadsheet and open your existing .xlsx workbook.
  2. 2. Sort the data securely: Navigate to the Data tab and use the Sort tool to organize your dataset by Code and then by Date.
  3. 3. Enter the formula: Apply your helper columns or type your complex array formula to evaluate consecutive date sequences >= 3.
  4. 4. Calculate the result: Press Enter (or Ctrl+Shift+Enter for legacy arrays) to instantly calculate your sums filtered by Year and Code.
100% compatible with Microsoft Excel formulas and .xlsx filesSupports advanced array formula confirmation (Ctrl+Shift+Enter) and native dynamic arraysLightweight, fast execution for large chronological datasets
microsoft office alternative - wps office

Frequently Asked Questions

Why is my array formula showing a #VALUE! error?

This usually happens in legacy versions of Excel if you press Enter instead of pressing Ctrl+Shift+Enter. The application fails to process the array dimensions correctly without that specific confirmation.

How can I filter a date range by year inside a formula?

You can wrap your date range in the YEAR() function within an IF statement or array (e.g., IF(YEAR(B2:B100)=2023)). Alternatively, you can create a 'Year' helper column and use standard SUMIFS criteria.

Is it possible to solve consecutive date problems without helper columns?

Yes, but it requires highly complex array formulas using functions like FREQUENCY, IF, and SUM to evaluate gaps between dates in memory. Helper columns are generally recommended for readability and easier maintenance.