Match two columns (one approximate) in excel and return a third

pernorman

New Member
Joined
Jan 16, 2015
Messages
3
Hello Excel experts!

I consider myself an expert user of Excel but I really got stuck on this problem :confused: . I prefer a solution with built-in formulas but if that isn't possible a VBA solution is fine.

I have one table (the Rating table) where I occasionally put in data that is event driven: e.g. a change in a banks credit rating. That happens once in a while and I am recording the bank, actual date that the credit rating was changed, and the credit rating. In the second table (the Lookup table) I have daily cash balance with each bank and would like to tag each balance with the relevant rating of that bank. This means that I would like to search for the row in the Rating table that matches the bank and the date that is closest i.e. equal to or less than the cash balance date. Please see the tables below.

Rating Table

BankDateRating
Citibank01/05/2014A+
RBS01/05/2014A
Citibank05/03/2014AA
Citibank08/30/2014A-
RBS08/30/2014A-

<tbody>
</tbody>

Lookup table


DateCash balanceBankRatingAnswer:
03/31/20141000CitibankFormula here...A+
03/31/20142000RBSFormula here...A
06/30/20143000CitibankFormula here...AA
06/30/20144000RBSFormula here...A
09/30/20145000CitibankFormula here...A-
09/30/20146000RBSFormula here...A-

<tbody>
</tbody>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the board!

With your rating table copied to A1:C6 and lookup table to A9:E15 (including headers), the following formula works for me.

=INDEX($C$2:$C$6,MATCH(2,1/(($A$2:$A$6=C10)*($B$2:$B$6<=A10))))

Note that this must be array confirmed using Shift, Ctrl & Enter, otherwise it will return a #VALUE! error.

edit:-

forgot to mention that the lookup table needs to have the dates ascending, otherwise it will take the last date in the list that is on or before the reference date, even if that is not the most recent.
 
Last edited:
Upvote 0
Wow! How that worked, I have no idea.. Much appreciated though!!

Can you please explain the logic behind the formula!??
 
Upvote 0
Sure, or I'll try to anyway

($A$2:$A$6=C10) works in the same way as a formula using =IF(x=y,true,false), in that matching rows return TRUE, likewise for the subsequent part, ($B$2:$B$6<=A10).

Remembering the way that logical functions work, TRUE = 1, FALSE = 0, so the results are multiplied, TRUE*TRUE = 1, anything else = 0, so you end up with an array, {0,1,0,1,1,0} or something similar.

Then the array is used as a divisor, 1/1 = 1, 1/0 = #DIV/0! error. The MATCH function will ignore the errors caused by the non matching rows and find the last number (using approximate match, exact match would find the first record, not last!) , which will be the last row with an exact match for the bank name (=C10) and an approximate match for the date(<=A10).

Hope that makes sense, the formula is easier to write than to explain.
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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