Forum Discussion
JMunoz4
Feb 12, 2021Copper Contributor
Help - Find the 2nd match using Xlookup
Is there a way using XLookup to return the 2nd (or 3rd, or 4th, or whatever) match in the lookup value? I'm also trying to use as few helper columns as I can. Otherwise I'd just use the VLookup funct...
excelmee
Jun 24, 2021Copper Contributor
It seems possible. Here is an example.
Formula:
=XLOOKUP(
F2:F5&H1,
B1:B16&
SORTBY(
SEQUENCE(ROWS(B1:B16),1,2)-MATCH(SORT(B1:B16),SORT(B1:B16),0),
SORTBY(SEQUENCE(ROWS(B1:B16),1,2),B1:B16,1),1
),
C1:C16
)
https://excelmee.com/excel-formulas/lookup/xlookup-nth-occurrence-in-excel-first-last-and-nth/
LSpurchasing
Aug 31, 2021Copper Contributor
excelmee
Would this formula need to be revised to find the nth result when using only one lookup value (F2)? I tried the formula you posted and it didn't work in such a case.
Would this formula need to be revised to find the nth result when using only one lookup value (F2)? I tried the formula you posted and it didn't work in such a case.
- excelmeeAug 31, 2021Copper Contributor
LSpurchasing You just need to change F2:F5&H1 to F2&H1.
If you have a single search key better follow the Index + Filter combo.
- SergeiBaklanAug 31, 2021Diamond Contributor
If you need nth occurrence, the easiest way is based on what PeterBartholomew1 suggested
- MobileTimJan 20, 2023Copper Contributor
Thank you PeterBartholomew1 and SergeiBaklan saved me a ton of time today. Appreciate this community.
- SergeiBaklanJan 21, 2023Diamond Contributor
MobileTim , glad to know this forum helped
- LSpurchasingAug 31, 2021Copper Contributor
Perfect! Thanks