Calculation Issues

How to Sum Consecutive Excel Values Until a Condition Changes

Olivia MillerOlivia Miller Nov 11, 2026 868 views

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.

How to Sum Consecutive Excel Values Until a Condition Changes in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the target cell

Click on the cell where you want the consecutive sum result to appear.

2
Enter the XMATCH and TAKE formula

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.

3
Calculate the result

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 TAKE and XMATCH Functions (Excel 365)
Dynamic Array Compatibility: This formula relies on dynamic arrays available in Excel 365 and Excel for the Web. It does not require Ctrl+Shift+Enter.
Advanced Spreadsheet Features

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. 1. Open your dataset in WPS: Launch WPS Spreadsheet and open the workbook containing your sequential data.
  2. 2. Verify data sorting: Ensure your rows are sorted chronologically so the consecutive streak formulas work accurately.
  3. 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. 4. Press Enter: Hit Enter to instantly calculate the sum of your consecutive values until the condition changes.
100% compatibility with Microsoft Excel formulas and .xlsx file formatsNative support for modern dynamic array functions and advanced data slicingLightweight, fast-loading, and completely free to use for daily data analysis
microsoft office alternative - wps office

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.