Group Date Ranges by Flag in Excel Using Formulas
Question details
Summarize consecutive rows of start dates, end dates, and buffer flags in a separate table.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user wants one summary row for each consecutive group of records with the same buffer flag.
- Observed behavior
- Each summary row should show the first start date, the last end date, and the group's flag.
Arrange the records in the order you want to group them, with no blank rows between records. The example assumes start dates in F, end dates in G, flags in H, and data beginning in row 3; adjust the references if your layout differs.
Use a Helper Column and Formulas to Summarize Consecutive Flags
Use this formula approach when you want a summary table without writing a macro.
A new group begins whenever the flag changes from the preceding row. The formulas group consecutive rows by flag; they do not split a group because of gaps between dates.
The example covers rows 3 through 1000. Extend all matching ranges if your data goes beyond row 1000.
In I3, enter =IF(F3="","",1). In I4, enter =IF(F4="","",IF(H4=H3,I3,I3+1)), then fill I4 down through I1000.
Enter First Date in J2, Last Date in K2, and Flag in L2.
In J3, enter =IFERROR(INDEX($F$3:$F$1000,MATCH(ROWS($J$3:J3),$I$3:$I$1000,0)),"").
In K3, enter =IF(J3="","",INDEX($G$3:$G$1000,IFERROR(MATCH(ROWS($J$3:J3)+1,$I$3:$I$1000,0)-1,COUNT($I$3:$I$1000)))).
In L3, enter =IF(J3="","",INDEX($H$3:$H$1000,MATCH(ROWS($J$3:J3),$I$3:$I$1000,0))). Select J3:L3 and drag the fill handle down far enough to cover all groups.
Select columns J and K, then use Home > Number Format to apply a date format.
Build the Same Flag-Based Summary in WPS Spreadsheets
Use a helper column and INDEX and MATCH formulas in WPS Spreadsheets to summarize consecutive date ranges by flag.
- 1. Open and arrange the workbook: Open your workbook in WPS Spreadsheets. Arrange the records with start dates in F, end dates in G, flags in H, and the first record in row 3.
- 2. Number the groups: Enter =IF(F3="","",1) in I3 and =IF(F4="","",IF(H4=H3,I3,I3+1)) in I4. Fill I4 down through I1000.
- 3. Find the first dates: Add headings in J2:L2. In J3, enter =IFERROR(INDEX($F$3:$F$1000,MATCH(ROWS($J$3:J3),$I$3:$I$1000,0)),"").
- 4. Find the last dates and flags: In K3, enter =IF(J3="","",INDEX($G$3:$G$1000,IFERROR(MATCH(ROWS($J$3:J3)+1,$I$3:$I$1000,0)-1,COUNT($I$3:$I$1000)))). In L3, enter =IF(J3="","",INDEX($H$3:$H$1000,MATCH(ROWS($J$3:J3),$I$3:$I$1000,0))).
- 5. Complete the summary: Fill J3:L3 down to cover all groups, then select columns J and K and apply a date format from the Home tab.

Frequently Asked Questions
What starts a new date-range group?
In the example, a new group starts when the value in column H differs from the preceding row's flag. Identical flags separated by a different flag form separate groups.
Do gaps between dates create separate groups?
No. These formulas group consecutive rows by flag only. Splitting groups at date gaps requires an additional date-continuity test in the helper formula.
Why do the summary dates appear as numbers?
Spreadsheet dates are stored as numbers. Select the summary date columns and choose a date format from the Home tab's number-format controls.
What if my data extends beyond row 1000?
Fill the helper formula down to your last data row and change every $1000 endpoint in the summary formulas to the same new endpoint.
Can I use Power Query instead?
Yes. In Excel, select the source data and choose Data > From Table/Range. A Power Query solution can identify consecutive flag changes and summarize each resulting group, which can be useful for repeatable imports.




