Formula Errors

Create Year-Based Sequence Numbers That Stay with Rows in Excel

Kushani NimanthikaKushani Nimanthika Nov 18, 2026 869 views

Question details

Create sequence numbers that restart each year and remain associated with the correct records when sorted.

Create Year-Based Sequence Numbers That Stay with Rows in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains dated records that need a chronological sequence within each year.
Observed behavior
Each record should receive a year-specific sequence number based on its complete timestamp, including after the records are sorted.
Before you start

Ensure the timestamps are real Excel date-and-time values, not text, and that each record has the correct year. Add a unique numeric ID for each record to break ties when timestamps match.

Solution 1Recommended

Calculate a chronological sequence for each year

Use COUNTIFS with the full timestamp and a unique ID so the sequence does not depend on the current row order.

This example uses timestamps in column A, years in column B, unique numeric IDs in column C, and sequence numbers in column D. Adjust every $2:$1000 range to cover all your records.

1
Enter the formula

In cell D2, enter =COUNTIFS($B$2:$B$1000,B2,$A$2:$A$1000,"<"&A2)+COUNTIFS($B$2:$B$1000,B2,$A$2:$A$1000,A2,$C$2:$C$1000,"<="&C2).

2
Fill the sequence column

Drag the fill handle from D2 down through the last record. Each year starts at 1, and records with matching timestamps are ordered by their numeric IDs.

3
Sort the complete records

Select the entire data range, including the sequence column, and use Data > Sort to sort by timestamp or another field. Keep all columns together when prompted.

Calculate a chronological sequence for each year
Sequences can recalculate: Adding or changing records can change chronological sequence numbers. Expand the formula ranges when records extend beyond row 1000.
Work with sequences in WPS

Create year-based sequences in WPS Spreadsheets

Use COUNTIFS in WPS Spreadsheets to number records by year and timestamp, then sort the complete table or paste the results as values.

  1. 1. Open the workbook: Open your Excel workbook in WPS Spreadsheets and arrange timestamps, years, and unique numeric IDs in columns A, B, and C.
  2. 2. Enter the formula: In D2, enter =COUNTIFS($B$2:$B$1000,B2,$A$2:$A$1000,"<"&A2)+COUNTIFS($B$2:$B$1000,B2,$A$2:$A$1000,A2,$C$2:$C$1000,"<="&C2), adjusting the ranges to cover your data.
  3. 3. Fill and sort: Drag the fill handle down the sequence column, then select the entire table and use Data > Sort to sort the records.
  4. 4. Fix numbers if needed: Copy the sequence cells and use Paste Special > Values to make the assigned numbers permanent.
Restart chronological sequence numbers for each yearUse a unique ID to order matching timestampsOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interface for formulas and sorting
microsoft office alternative - wps office

Frequently Asked Questions

Why do records with the same timestamp need an ID?

A timestamp alone cannot determine which matching record comes first. Give each record a unique numeric ID in column C so the formula can use it as a tie-breaker.

Can I sort by another column without losing the sequence?

Yes. Select the entire data range, including the sequence column, before using Data > Sort. Do not sort the sequence column by itself.

Will the numbers change when I add a record?

Formula results can change if a new record falls earlier in the same year's chronological order. Copy the sequence cells and use Paste Special > Values if the assigned numbers must stay fixed.

How do I create the year column from a timestamp?

If the timestamp is in A2, enter =YEAR(A2) in B2 and fill the formula down. The timestamp must be a valid Excel date-and-time value.