Assign Same Sequential Numbers to Duplicates in a List in Google Sheets

Published on

Here’s a handy Google Sheets tip—how to assign the same sequential number to duplicate values in a list using an array formula. This works great with grouped or categorized data.

For example, if the item “Cherry” first appears in row 3, all its duplicates should get the number 3—not 4, 5, etc.

This tutorial explains how to generate the same sequential number for duplicate values using an array formula that works whether your list is sorted or unsorted.

Assigning Sequential Numbers to Duplicates – Single Column Example

Let’s begin with a simple example.

Example of assigning same sequential numbers to duplicate values in a single column in Google Sheets

In column B, you have a list of items—some repeated. We want to assign sequential numbers in column A so that all duplicates share the same number as their first appearance.

The Array Formula

Place the following formula in cell A2 and ensure the column below it is blank:

=ArrayFormula(IF(LEN(B2:B), XMATCH(B2:B, UNIQUE(B2:B)), ))

This formula assigns the same sequential number to each unique item. All “apple” entries get 1, “orange” gets 2, and so on.

How the Formula Works

Let’s break it down:

1. UNIQUE(B2:B) returns the first instance of each unique item:

apple  
orange  
cherry  
mango  
banana  

2. XMATCH(B2:B, UNIQUE(B2:B)) checks the position of each item in this list:

  • All “apple” → 1
  • All “orange” → 2
  • And so on.

3. The outer IF(LEN(...)) ensures the formula only runs for non-blank rows, helping it auto-expand without errors.

Tip: If you’re working with a fixed list, say B2:B12, you can simplify the formula to:

=ArrayFormula(XMATCH(B2:B12, UNIQUE(B2:B12)))

Why Not Use the Classic IF Formula?

You might be familiar with this common approach:

  1. Type 1 in cell A2
  2. In A3, enter:
    =IF(B2=B3, A2, A2+1)
  3. Drag it down the column.

This assigns the same number to duplicate items—but only if the list is sorted. It compares each item with the one below and increments the number only when the value changes.

However, if the list is unsorted or new duplicates are added later, the numbering breaks. For example, if you add “apple” again in row 13, it won’t get the same number as earlier “apple” entries.

That’s why the array formula approach is far more robust and dynamic.

Assigning Same Sequential Numbers to Multi-Column Duplicates in Google Sheets

Now, what if duplicates are based on two columns, such as item name (B2:B) and grade (C2:C)? In that case, we need to check both columns together.

Example of assigning same sequential numbers to duplicates based on two columns in Google Sheets (e.g., item and grade)

Multi-Column Array Formula

=ArrayFormula(IF(LEN(B2:B), XMATCH(B2:B & C2:C, UNIQUE(B2:B & C2:C)), ))

This formula combines columns B and C into one string (B2:B&C2:C) and finds the position of each unique combination. All identical combinations get the same number.

Conclusion

You’ve now learned how to:

  • Assign the same sequential number to duplicate entries
  • Handle both single-column and multi-column duplicates
  • Use array formulas that auto-expand and work on unsorted lists

Additional Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

2 COMMENTS

  1. Hey, thanks for these amazing formulas.

    Is there any way the formula =ArrayFormula(match(F2:F2103,unique(F2:F2103),0))
    can start numbering from the bottom to the top of the sheet?

    Any help would be greatly appreciated, thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.