How to Add a Sequential Index by Group in Excel
Question details
The user needs to assign a running sequential index to grouped items within a spreadsheet table.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Numbering and organizing grouped items within a table while preserving the original dataset order, enabling data to be restored without repeatedly sorting.
- Observed behavior
- Requires a dynamic formula or tool to calculate a running index based on specific group criteria that automatically updates or calculates row-by-row.
Ensure your dataset is organized in a clear tabular format, and verify whether your groups are already sorted together or mixed throughout the table, as this determines the most efficient method to use.
Use the COUNTIF Function for a Running Count
This is the most versatile method for adding a running index by group, working perfectly whether your data is pre-sorted or mixed.
By utilizing an expanding range in the COUNTIF function, you can count the occurrences of a specific item up to the current row. This automatically generates a sequential index for each group.
Click on the cell in the first data row where you want the sequential index to begin (for example, B2, assuming your group criteria is in column A).
Type the formula =COUNTIF($A$2:A2, A2) and press Enter. If you are using an official Excel Table, use the structured reference like =COUNTIF(Table1[[#Headers],[GroupColumn]]:[@GroupColumn],[@GroupColumn]).
Click the cell with the formula, then click and drag the fill handle (the small square at the bottom-right corner) down to apply the sequence to the rest of your data.

Use an IF Formula for Pre-Sorted Data
If your table is already grouped and sorted by the criteria column, a simple IF function evaluates much faster, making it ideal for large datasets.
Use Power Query for Massive Datasets
For exceptionally large datasets where formulas might cause performance issues, Power Query provides an efficient way to group and index data.
Easily Add Sequential Indexes Using WPS Spreadsheet
WPS Spreadsheet fully supports advanced formulas like COUNTIF, IF, and dynamic arrays, empowering you to effortlessly calculate running indexes and manage grouped data without any lag.
- 1. Open your dataset: Launch WPS Spreadsheet and open the document containing the grouped data you wish to index.
- 2. Select the index cell: Click into the empty cell next to your first data entry where the sequential number should appear.
- 3. Type the formula: Input =COUNTIF($A$2:A2, A2) (replacing A with your target group column) and press Enter.
- 4. Fill the column: Double-click the small square at the bottom right corner of the active cell to automatically fill the formula down to the bottom of your dataset.

Frequently Asked Questions
Can I add a sequential index based on multiple criteria?
Yes, you can use the COUNTIFS function to specify multiple conditions. For example, =COUNTIFS($A$2:A2, A2, $B$2:B2, B2) will calculate a running index based on unique combinations of groups in both Column A and Column B.
Why is my sequential index returning 1 for every row?
This usually happens if the range reference in your COUNTIF formula is entirely absolute (e.g., $A$2:$A$20). To create a running sequence, you must use a mixed reference like $A$2:A2, where only the starting row is locked with a dollar sign so the range expands as you drag it down.
Does this method work with structured table references?
Yes. If your data is formatted as an official Table, you can use structured references. The formula would look like =COUNTIF(Table1[[#Headers],[GroupColumn]]:[@GroupColumn],[@GroupColumn]), ensuring the range expands dynamically within the table.




