How to Sum Consecutive Excel Values Until a Condition Changes
Question details
The user wants to sum a range of values consecutively based on a specific condition, but needs the calculation to stop immediately as soon as the condition is no longer met, ignoring any matching rows that appear later in the dataset.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Calculating the total duration or sum of an initial unbroken streak of matching criteria (e.g., a rating of 5) without including isolated matches further down the list.
- Observed behavior
- A standard SUMIFS function calculates all matching rows in the dataset, failing to stop at the first condition change.
Ensure your dataset is sorted chronologically or in the specific logical order required for your sequence, as these formulas rely strictly on row positioning to determine where the streak ends.
Use TAKE and XMATCH Functions (Excel 365)
Best for modern Excel versions, using dynamic array functions to easily slice the data until the streak condition breaks.
The XMATCH function can dynamically identify the first instance where your condition fails. Combined with the TAKE function, it allows you to extract and sum only the rows preceding that failure point.
Click on the cell where you want the consecutive sum result to appear.
Input the formula: =SUM(TAKE($L$5:$L$10000,XMATCH(TRUE,$K$5:$K$10000<>5)-1)). Adjust $L$5:$L$10000 to your sum range and $K$5:$K$10000 to the column containing your condition.
Press Enter. The formula will automatically locate the first row that does not equal 5 and sum all values in column L above that row.

Use INDEX and AGGREGATE (Older Excel Versions)
A robust alternative for Excel 2010 through 2019 that do not support modern dynamic array functions like TAKE.
Calculate Complex Formulas Seamlessly with WPS Office
WPS Spreadsheet fully supports advanced array formulas and functions like TAKE, XMATCH, and AGGREGATE. You can easily sum consecutive values and perform complex data analysis using a lightweight, intuitive interface.
- 1. Open your dataset in WPS: Launch WPS Spreadsheet and open the workbook containing your sequential data.
- 2. Verify data sorting: Ensure your rows are sorted chronologically so the consecutive streak formulas work accurately.
- 3. Input the formula: Type the =SUM(TAKE(...)) or INDEX/AGGREGATE formula into your desired result cell, identical to how you would in Excel.
- 4. Press Enter: Hit Enter to instantly calculate the sum of your consecutive values until the condition changes.

Frequently Asked Questions
Why doesn't the standard SUMIFS function work for this scenario?
SUMIFS evaluates the entire specified range and sums every single row that matches your criteria, regardless of its position. It does not have the logical capability to stop calculating when a consecutive streak is broken by a non-matching value.
Can I add additional criteria to the AGGREGATE formula?
Yes. You can multiply multiple conditions in the denominator of the AGGREGATE function (for example: (Range1<>5)*(Range2="Category")). This allows you to evaluate multiple criteria before defining the row where the sequence breaks.
What happens if the condition never changes in my dataset?
If the condition is met for all rows in the dataset, functions looking for a failure (like searching for <>5) will not find a match and may return a #N/A or #NUM! error. You can wrap your formula in an IFERROR function to fallback to a standard SUM in this edge case.




