Function Problems

Add an Occurrence Number to Repeated Items in Excel

Amos GikundaAmos Gikunda Dec 2, 2026 869 views

Question details

Generate a sequential occurrence number for each repeated item and combine it with a prefix and part of the original value.

Add an Occurrence Number to Repeated Items in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains item values in a column, and each occurrence needs a formatted identifier.
Observed behavior
Each identifier should include a fixed prefix, the first two characters of the item, and the item's occurrence number.
Before you start

Place the item values in column B starting at B2, and leave column A available for the identifiers. If your data starts in a different cell, adjust the formula references to match.

Solution 1Recommended

Use COUNTIF to Number Each Occurrence

Use this formula to count each item's appearances from the first data row through the current row.

1
Enter the formula

Select cell A2 and enter ="01-"&LEFT(B2,2)&"-"&COUNTIF(B$2:B2,B2).

2
Fill the formula down

Select A2 and drag the fill handle down alongside the values in column B. You can also double-click the fill handle to fill the adjacent data range.

3
Check the identifiers

Review column A. For example, repeated values beginning with AB produce identifiers such as 01-AB-1 and 01-AB-2.

Use COUNTIF to Number Each Occurrence
How the count works: COUNTIF compares the full value in column B, not just its first two characters. The occurrence number depends on the current row order.
Number repeated items

Create Occurrence Numbers in WPS Spreadsheet

Use the same LEFT and COUNTIF formula in WPS Spreadsheet to build a prefixed identifier for each occurrence of an item.

  1. 1. Open your worksheet: Open WPS Spreadsheet and use Open to select your Excel workbook.
  2. 2. Enter the formula: With item values starting in B2, select A2 and enter ="01-"&LEFT(B2,2)&"-"&COUNTIF(B$2:B2,B2).
  3. 3. Fill the remaining rows: Select A2 and drag its fill handle down alongside the items in column B.
  4. 4. Save the workbook: Choose Menu > Save As and select an Excel format such as XLSX.
Number repeated items as you fill the formula downCustomize the prefix and number of characters includedOpen and save Microsoft Excel XLSX filesWork with formulas in a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

How do I change the prefix in the identifier?

In the formula in A2, replace "01-" with your preferred text, such as "ITEM-", and fill the updated formula down.

Can I include more than two characters from the item?

Yes. Change LEFT(B2,2) to LEFT(B2,3) for the first three characters, then fill the formula down.

Does the formula count items with the same first two characters together?

No. COUNTIF uses the full value in column B as its criterion. Two different values can have the same displayed first two characters but separate occurrence counts.

Will sorting the rows change the occurrence numbers?

It can. The formula counts occurrences from the first data row to the current row, so recalculation after sorting may assign numbers in a different order.