How to Get Nth Match in Excel

Learn multiple Excel methods to get nth match with step-by-step examples and practical applications.

excelformulaspreadsheettutorial
12 min read • Last updated: 7/2/2025

How to Get Nth Match in Excel

Why This Task Matters in Excel

In the real world, data almost never arrives in a tidy format where each lookup value is unique. Sales logs record multiple orders from the same customer, inventory sheets list the same product received on different dates, and help-desk systems capture many tickets filed by the same employee. In all these cases you eventually need to retrieve the first, second, or nth occurrence that matches a certain criterion.

Imagine a customer service manager who wants to review the third complaint filed by a customer to see if issues are escalating. Or think of a supply-chain analyst who must pull the fifth shipment date for a SKU to check service-level compliance across repeated deliveries. Financial auditors often sample the nth transaction that matches a risk flag to satisfy statutory compliance tests. In marketing, analysts compare the second purchase of each buyer to evaluate repeat-purchase patterns. Across industries, “nth match” lookups are indispensable for event sequencing, sampling, and longitudinal analysis.

Excel is perfectly suited for this requirement because its worksheet functions can “filter,” “rank,” and “index” rows dynamically. With modern dynamic-array functions, you can spill all matches of a criterion and simply pick the nth item. For users on older Excel versions, classic array formulas using SMALL, IF, and INDEX still deliver rock-solid results. Mastering the technique strengthens core lookup skills, deepens your understanding of array calculations, and teaches valuable debugging habits such as checking row offsets and validating sample sizes.

If you do not learn how to get the nth match, you will resort to manual filtering, copy-pasting, or writing error-prone helper columns—tasks that are slow, brittle, and unacceptable in professional dashboards. Moreover, automated reporting pipelines, Power Query transformations, and VBA macros often feed downstream models that assume precise indexing of repeated values. Therefore, proficiency in nth-match retrieval is a foundational capability that unlocks advanced reporting, audit-trail analysis, and time-series modelling on transactional data.

Best Excel Approach

The fastest, most transparent method in modern Microsoft 365 or Excel 2021 is to use FILTER to capture all matching rows and then feed that spill range into INDEX (or TAKE, CHOOSEROWS, etc.) to isolate the required position.

=INDEX(
      FILTER(ReturnRange, CriteriaRange=LookupValue, "No match"),
      NthPosition
)

Why this is ideal:

  1. ClarityFILTER states the condition explicitly, avoiding nested row math.
  2. Dynamic – New rows that satisfy the condition automatically spill into the result, so the nth position updates without helper columns.
  3. Maintenance-friendly – You can reference the filtered list elsewhere, chart it, or wrap additional functions around it.

When to use:

  • You have Microsoft 365 / Excel 2021+ where dynamic arrays are supported.
  • The dataset is not extremely large (less than roughly one million filtered items) or performance is acceptable.
  • You prefer readability and minimal nested logic.

Legacy alternative (Excel 2010-2019): a single-cell array formula with SMALL and IF:

=INDEX(ReturnRange,
       SMALL(
             IF(CriteriaRange=LookupValue,
                ROW(CriteriaRange)-MIN(ROW(CriteriaRange))+1),
             NthPosition))

This formula must be confirmed with Ctrl+Shift+Enter in versions before 365, but it works everywhere and does not require spill behaviour. It is preferable whenever FILTER is unavailable or when you must deploy the workbook to mixed Excel environments.

Parameters and Inputs

Before writing the formula, gather these inputs:

  1. CriteriaRange – The column (or row) containing repeated values you want to test, e.g., [A2:A1000] with Customer IDs (Text or Numeric).
  2. ReturnRange – The parallel column whose nth item you want back, e.g., [B2:B1000] for Order Dates. It must be the same size and shape as CriteriaRange.
  3. LookupValue – The specific value you are matching, such as "C005" or 103.
  4. NthPosition – A positive integer (1, 2, 3, …) entered manually, in a cell, or computed. Non-integers will lead to #VALUE!.
  5. Optional Default – The string "No match" in the FILTER example acts as a fallback when the criteria returns fewer than N matches.
  6. Range Preparation – Remove blank rows inside your dataset or use FILTER to ignore them, especially if blanks can falsely satisfy conditions in SMALL formulas.
  7. Edge Cases – Decide how to react when NthPosition exceeds the count of matches. Modern formulas return #NUM! or your default string; legacy array formulas return #NUM!. You can trap this with IFERROR.

Always validate that CriteriaRange and ReturnRange are aligned row-by-row; mismatches create off-by-one errors that are hard to spot.

Step-by-Step Examples

Example 1: Basic Scenario

Goal – Retrieve the second purchase amount for customer "C003" in a small table.

Sample Data (placed in [A1:C9])

CustomerDateAmount
C0012023-01-05120
C0022023-01-06185
C0032023-01-07250
C0012023-02-02130
C0032023-02-18300
C0022023-02-20215
C0032023-03-04275
C0042023-03-06190

Step-by-Step:

  1. In cell E1 type Lookup Customer and in E2 enter "C003".
  2. In F1 type Nth Purchase and in F2 enter 2.
  3. In G1 type 2nd Amount.
  4. In G2 enter:
=INDEX(
      FILTER(C2:C9, A2:A9=E2, "No match"),
      F2)

Explanation:

  • FILTER(C2:C9, A2:A9=E2, "No match") spills [250,300,275].
  • INDEX(...,F2) picks the second element (300).

Result: 300 displays in G2.
Why it works: FILTER narrows the list to matching rows, preserving order. INDEX then counts down the list without extra math.

Common variations:

  • Return the nth date by changing the ReturnRange to B2:B9.
  • Make N dynamic by referencing a formula such as COUNTIF(A2:A9,E2) to get the last match automatically.

Troubleshooting:

  • If G2 shows "No match", ensure your NthPosition does not exceed the length of the spill.
  • If you see #VALUE!, verify F2 contains a valid integer. Non-numeric entries will fail.

Example 2: Real-World Application

Scenario – A human resources analyst tracks multiple leave requests by employee. She must retrieve the fifth leave date for each staff member to check who is approaching the annual leave cap.

Dataset (simplified) spans [A1:E2000]:

EmpIDLeaveTypeStartDateEndDateDays

There are up to 15 leave records per employee. The analyst sets up a summary sheet with:

  • Cell B2 – dropdown of unique EmpIDs using Data Validation.
  • Cell C2 – numeric input “Nth Leave”.
  • Cell D2 – result field “Nth Start Date”.

Formula in D2 (dynamic array version):

=INDEX(
       TAKE(
            FILTER(StartDateColumn, EmpIDColumn=B2, ""),
            C2, 1),
       1)

However, TAKE is optional. A simpler universal formula is:

=INDEX(
      FILTER(StartDateColumn, EmpIDColumn=B2, ""),
      C2)

Step-by-step logic:

  1. FILTER(StartDateColumn, EmpIDColumn=B2, "") spills all start dates for the chosen employee.
  2. INDEX(...,C2) extracts row number C2 (e.g., 5) from that spill.

Business impact: The analyst instantly sees who has scheduled five or more leaves. She adds Conditional Formatting to flag dates occurring late in the fiscal year, enabling proactive discussions with managers.

Integration: The same formula is used inside a PivotTable calculated field with the new dynamic array engine, and later passed to Power BI as a workbook parameter.

Performance note: Even with 2000 rows, FILTER evaluates instantly. For 100k+ rows, convert the dataset to an Excel Table and reference structured names, which improves readability and sometimes speed.

Example 3: Advanced Technique

Challenge – Finance wants the third debit amount greater than 10 000 for each account across a 50 000-row ledger where values and criteria differ between columns.

Advanced criteria demand both a match (AccountID) and a numeric threshold (Amount greater than 10000). Dynamic array formula:

=LET(
     Account,   Ledger[AccountID],
     Amount,    Ledger[Amount],
     TargetID,  G2,              /* lookup value */
     N,         H2,              /* nth position */
     Matches,   FILTER(Amount, (Account=TargetID)*(Amount>10000)),
     INDEX(Matches, N))

Explanation:

  • LET names ranges for efficiency and clarity.
  • (Account=TargetID)*(Amount greater than 10000) multiplies the two Boolean arrays, returning TRUE only where both conditions hold.
  • FILTER spills just the qualifying debit amounts.
  • INDEX pulls the nth one.

Edge-case handling: Wrap the final INDEX in IFERROR to return "Not enough hits" when fewer than N matches exist.

=IFERROR(INDEX(Matches,N),"Not enough hits")

Performance optimisations:

  • Use -- instead of multiplication if desired.
  • Disable full-book calculation until final testing to avoid re-calculations on every keystroke.
  • Store heavy formulas in helper worksheets and point dashboards to them, reducing front-end load.

Professional tip: Convert Ledger to an Excel Table so field names like Ledger[Amount] auto-expand as new rows get appended from monthly imports.

Tips and Best Practices

  1. Use Excel Tables – Structured references (Table1[Column]) expand automatically, eliminating range edits.
  2. Trap Errors Early – Wrap outer IFERROR to return clear messages such as "Not enough occurrences" rather than cryptic #NUM!.
  3. Keep N in a Separate Cell – This aids what-if analysis and prevents hard-coding that hides logic.
  4. Cache Heavy Filters with LET – Naming subexpressions reduces duplicate calculations in complex workbooks.
  5. Document Range Pairs – Always note that CriteriaRange and ReturnRange must align row-by-row; mismatched sizes produce silent inaccuracies.
  6. Combine with UNIQUE – If you only need distinct nth elements, spill UNIQUE inside FILTER before indexing.

Common Mistakes to Avoid

  1. Mismatched Range Sizes
    Users often select CriteriaRange [A2:A100] but ReturnRange [B2:B99]. Excel may spill #N/A or frame incorrect rows. Always verify bottom-row numbers.
  2. Forgetting to Confirm Legacy Array Formulas
    Before Excel 365, you must press Ctrl+Shift+Enter. If you press only Enter, Excel shows the formula text or a #NAME? error.
  3. Using Relative Row Math Inside Tables
    ROW(Table1[Col])-ROW(Table1[Col])+1 breaks when the header row is hidden. Prefer SEQUENCE or XMATCH alternatives, or use dynamic arrays.
  4. Ignoring Case Sensitivity with Text
    FILTER and = comparisons are case-insensitive, whereas FIND is case-sensitive. Decide which behaviour you need and document it.
  5. Underestimating N
    Requesting the 10th match when only nine exist returns errors that propagate through dashboards. Always wrap IFERROR or compare COUNTIF to N first.

Alternative Methods

MethodCore FunctionsProsConsBest When
FILTER + INDEXModern dynamic arraysIntuitive, maintenance-friendly, no array entryRequires Microsoft 365/2021, spills intermediate dataYou control the environment or audience has modern Excel
SMALL + IF + INDEXClassic array formulaWorks in all Excel versions from 2007 onwardHarder to read, needs Ctrl+Shift+Enter in older buildsWorkbooks shared with legacy users
Helper Column with Running CountCOUNTIFS, simple VLOOKUPEasiest to audit visually, no array formulasAdds columns, manual sort vigilance, sluggish on large dataWhen you can freely add columns and need transparency
Power QueryGUI interface with Index and Grouped RowsHandles millions of rows off-grid, refreshableNot real-time; users must click Refresh; learning curveETL workflows or scheduled data refreshes

Migration tip: Use Tables and structured references so converting from the SMALL approach to FILTER later involves only swapping the core formula, not re-selecting ranges.

FAQ

When should I use this approach?

Use an nth-match lookup whenever the dataset contains multiple rows per lookup key and you must retrieve a specific occurrence based on order, ranking, or sequence constraints. Typical triggers are auditing sequences, sampling records, and picking the latest or earliest event beyond the first.

Can this work across multiple sheets?

Yes. Qualify ranges with sheet names, e.g., Data!A2:A10000 as CriteriaRange. Dynamic arrays can spill across sheets only indirectly, so keep the formula on the destination sheet and pull ranges by reference. For legacy array formulas, cross-sheet ranges work identically.

What are the limitations?

FILTER may spill thousands of rows, which can become slow or unwieldy. Both FILTER and SMALL approaches assume an implicit sort based on original row order; if the data is unsorted, the “nth” might not reflect chronological order. Explicitly sort first with SORT or Table sorting.

How do I handle errors?

Wrap the outer INDEX in IFERROR or use the optional “if_empty” argument of FILTER. For legacy arrays, nest in IFERROR(..., "Not found"). Also pre-validate with COUNTIFS versus N to issue custom warnings before calculation.

Does this work in older Excel versions?

The SMALL + IF + INDEX array formula works in Excel 2007-2019. You must commit with Ctrl+Shift+Enter. FILTER, LET, TAKE, and other dynamic-array functions are available only in Microsoft 365/2021 and later.

What about performance with large datasets?

For up to roughly 100k rows, modern functions are fast on recent hardware. Beyond that, consider:

  • Storing the dataset as an Excel Table (in-memory optimisations).
  • Turning off automatic calculation while editing.
  • Using Power Query to stage data and loading only relevant columns to the sheet.
  • Employing helper columns with binary indicators to reduce spill sizes.

Conclusion

Retrieving the nth match in Excel bridges the gap between simple lookups and full database queries. By mastering dynamic-array techniques such as FILTER plus INDEX, or classic SMALL-style array formulas, you gain the flexibility to interrogate sequences, audit repeated events, and build dashboards that surface deeper insights from transactional data. These skills dovetail with sorting, advanced filtering, and conditional calculations—hallmarks of professional spreadsheet modelling. Keep practising with real datasets, experiment with edge-case error handling, and soon you will wield nth-match retrieval instinctively in every analysis task.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.