Reputation: 23
I'm trying to do matching between two spreadsheets using an Id and a Date field. I need an exact match on the ID, but the closest date that is greater than or equal to a date in the other table.
Specifically I'm trying to create the equivalent of the following SQL through a form of index(match) or Vlookup.
Select min(b.date)
from a
join b
on a.id = b.id
and b.date >= a.date
If I had access to Access I'd use that, but unfortunately its not an option, so its something I have to do in excel directly.
Any help would be greatly appreciated.
Upvotes: 0
Views: 171
Reputation: 152605
The following two formula will do what you want:
Array MIN(IF()):
=MIN(IF(($B$2:$B$15>=E2)*($A$2:$A$15=E1),$B$2:$B$15))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {}
Around the formula.
The Second uses AGGREGATE and gets entered normally:
=AGGREGATE(15,6,$B$2:$B$15/(($A$2:$A$15=E1)*($B$2:$B$15>=E2)),1)
NOTE
Neither formula require the data to be sorted.
Upvotes: 2