How to Get Nth Match in Excel
Learn multiple Excel methods to get nth match with step-by-step examples and practical applications.
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:
- Clarity –
FILTERstates the condition explicitly, avoiding nested row math. - Dynamic – New rows that satisfy the condition automatically spill into the result, so the nth position updates without helper columns.
- 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:
- CriteriaRange – The column (or row) containing repeated values you want to test, e.g., [A2:A1000] with Customer IDs (Text or Numeric).
- 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.
- LookupValue – The specific value you are matching, such as
"C005"or 103. - NthPosition – A positive integer (1, 2, 3, …) entered manually, in a cell, or computed. Non-integers will lead to
#VALUE!. - Optional Default – The string
"No match"in theFILTERexample acts as a fallback when the criteria returns fewer than N matches. - Range Preparation – Remove blank rows inside your dataset or use
FILTERto ignore them, especially if blanks can falsely satisfy conditions inSMALLformulas. - Edge Cases – Decide how to react when
NthPositionexceeds the count of matches. Modern formulas return#NUM!or your default string; legacy array formulas return#NUM!. You can trap this withIFERROR.
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])
| Customer | Date | Amount |
|---|---|---|
| C001 | 2023-01-05 | 120 |
| C002 | 2023-01-06 | 185 |
| C003 | 2023-01-07 | 250 |
| C001 | 2023-02-02 | 130 |
| C003 | 2023-02-18 | 300 |
| C002 | 2023-02-20 | 215 |
| C003 | 2023-03-04 | 275 |
| C004 | 2023-03-06 | 190 |
Step-by-Step:
- In cell E1 type Lookup Customer and in E2 enter
"C003". - In F1 type Nth Purchase and in F2 enter
2. - In G1 type 2nd Amount.
- 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 yourNthPositiondoes 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]:
| EmpID | LeaveType | StartDate | EndDate | Days |
|---|
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:
FILTER(StartDateColumn, EmpIDColumn=B2, "")spills all start dates for the chosen employee.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:
LETnames ranges for efficiency and clarity.(Account=TargetID)*(Amount greater than 10000)multiplies the two Boolean arrays, returning TRUE only where both conditions hold.FILTERspills just the qualifying debit amounts.INDEXpulls 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
- Use Excel Tables – Structured references (
Table1[Column]) expand automatically, eliminating range edits. - Trap Errors Early – Wrap outer
IFERRORto return clear messages such as"Not enough occurrences"rather than cryptic#NUM!. - Keep N in a Separate Cell – This aids what-if analysis and prevents hard-coding that hides logic.
- Cache Heavy Filters with LET – Naming subexpressions reduces duplicate calculations in complex workbooks.
- Document Range Pairs – Always note that CriteriaRange and ReturnRange must align row-by-row; mismatched sizes produce silent inaccuracies.
- Combine with UNIQUE – If you only need distinct nth elements, spill
UNIQUEinsideFILTERbefore indexing.
Common Mistakes to Avoid
- Mismatched Range Sizes
Users often select CriteriaRange [A2:A100] but ReturnRange [B2:B99]. Excel may spill#N/Aor frame incorrect rows. Always verify bottom-row numbers. - 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. - Using Relative Row Math Inside Tables
ROW(Table1[Col])-ROW(Table1[Col])+1breaks when the header row is hidden. PreferSEQUENCEorXMATCHalternatives, or use dynamic arrays. - Ignoring Case Sensitivity with Text
FILTERand=comparisons are case-insensitive, whereasFINDis case-sensitive. Decide which behaviour you need and document it. - Underestimating N
Requesting the 10th match when only nine exist returns errors that propagate through dashboards. Always wrapIFERRORor compareCOUNTIFto N first.
Alternative Methods
| Method | Core Functions | Pros | Cons | Best When |
|---|---|---|---|---|
FILTER + INDEX | Modern dynamic arrays | Intuitive, maintenance-friendly, no array entry | Requires Microsoft 365/2021, spills intermediate data | You control the environment or audience has modern Excel |
SMALL + IF + INDEX | Classic array formula | Works in all Excel versions from 2007 onward | Harder to read, needs Ctrl+Shift+Enter in older builds | Workbooks shared with legacy users |
| Helper Column with Running Count | COUNTIFS, simple VLOOKUP | Easiest to audit visually, no array formulas | Adds columns, manual sort vigilance, sluggish on large data | When you can freely add columns and need transparency |
| Power Query | GUI interface with Index and Grouped Rows | Handles millions of rows off-grid, refreshable | Not real-time; users must click Refresh; learning curve | ETL 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.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.