VLookup for the second instance

excelformulas

New Member
Joined
Feb 1, 2024
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to do a formula where I'm looking up the rate in a particular column in a table based on an ID number (first column). Each ID number shows up twice in teh table (once with $ amounts and then second with a rate). How do I do a vlookup formula to show me what is in column 3 the second time an ID is used? So If I did a vlookup for "123456789" in the below able for column 3 it shows 25,000,000 (which I need) but how do a separate formlua to show me 85.00 bps?
IDNameFirstNextNext
123456789​
Name 125,000,00050,000,000
123456789​
Name 1
85.00 bps​
60.00 bps​
50.00 bps​
987654321​
Name 225,000,00050,000,000
987654321​
Name 2
75.00 bps​
57.50 bps​
50.00 bps​
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the MrExcel board. What version of Excel are you using? You should update your profile to show that, as the version often determines which approach might be preferred.
 
Upvote 0
Welcome to the MrExcel board. What version of Excel are you using? You should update your profile to show that, as the version often determines which approach might be preferred.
Sorry I'm new to posting here. I just updated it but i have Professional Plus 2016 at work.
 
Upvote 0
Maybe something like this:
The formula in cell H3 will work in an Excel version from 2010 up.
Formula in H5 will work in Excel 365

Book2
ABCDEFGHI
1IDNameFirstNextNext2ID
2123456789Name 125,000,00050,000,000123456789
3123456789Name 185.00 bps60.00 bps50.00 bps85.00 bpsExcel 2010 and up
4987654321Name 225,000,00050,000,000
5987654321Name 275.00 bps57.50 bps50.00 bps85.00 bpsExcel 365
Sheet1
Cell Formulas
RangeFormula
H3H3=INDEX(Table1[First],AGGREGATE(14,6,(ROW(Table1[ID])-ROW(A2)+1)/(Table1[ID]=$H$2),1))
H5H5=INDEX(FILTER(Table1[First],Table1[ID]=H2),2)
 
Upvote 0
Here are a couple more options. One is close to that offered by @AhoyNC using INDEX/AGGREGATE. The other uses a conventional INDEX/MATCH, which finds the first match (you may already have that resolved), and then for the 2nd match (actually the last match), we can use a trick with LOOKUP to search for "2" in an array where it does not exist, so the function returns the last match. If you are certain that the last match in the table is the 2nd occurrence that you want, then this method should work too.
MrExcel_20240131_C (version 1).xlsx
ABCDEFGHI
1IDNameFirstNextNextLookup123456789123456789
2123456789Name 125,000,00050,000,0001st instance, col 32500000025000000
3123456789Name 185.00 bps60.00 bps50.00 bps2nd instance, col 385.00 bps85.00 bps
4987654321Name 225,000,00050,000,000
5987654321Name 275.00 bps57.50 bps50.00 bps
Sheet2
Cell Formulas
RangeFormula
H2H2=INDEX($C:$C,AGGREGATE(15,6,ROW(A:A)/($A:$A=$H$1),1))
I2I2=INDEX(C2:C5,MATCH($I$1,$A$2:$A$5,0))
H3H3=INDEX($C:$C,AGGREGATE(15,6,ROW(A:A)/($A:$A=$H$1),2))
I3I3=LOOKUP(2,1/(A:A=$I$1),C:C)
 
Upvote 0
For amount
Excel Formula:
=INDEX($C$2:$C$100,AGGREGATE(15,6,ROW($C$2:$C$100)/($A$2:$A$100=$A$2),1)-ROW($C$1))
For rate
Excel Formula:
=INDEX($C$2:$C$100,AGGREGATE(15,6,ROW($C$2:$C$100)/($A$2:$A$100=$A$2),2)-ROW($C$1))
 
Upvote 0
For amount
Excel Formula:
=INDEX($C$2:$C$100,AGGREGATE(15,6,ROW($C$2:$C$100)/($A$2:$A$100=$A$2),1)-ROW($C$1))
For rate
Excel Formula:
=INDEX($C$2:$C$100,AGGREGATE(15,6,ROW($C$2:$C$100)/($A$2:$A$100=$A$2),2)-ROW($C$1))
That works to get the 85 rate, but i need to copy this formula to others and have it pull the rate associated with that ID. SO how to i update the above formula to pull the correct rate if the IDs are different?
 
Upvote 0
Is the first ID in row 2 or your worksheet? The formula I offered doesn't depend on the row location, but the formula you've mentioned in post #7 does. It assumes data begin in row 2. Then to accommodate matching IDs as you move down row by row, you'll want to change the $A$2 reference. Assuming the ID's are in column A and they begin on row 2, then $A$2 should be changed to $A2. The "1" that appears after it returns the 1st match. For the next match, the 1 would be changed to 2.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top