Lookup Maximum Value Subject to Constraints

ncalenti

New Member
Joined
Aug 12, 2011
Messages
39
Ok, this has been killing me for a few days.
I have two tables
Number 1:
PK Date
A 1/1/2006
B 2/1/2009
C 3/1/2007
D 5/1/2007

Number 2:
PK Date
A 1/1/2005
A 2/1/2006
A 5/1/2009
B 2/1/2009
B 5/1/2010
C 5/1/2007
D 4/1/2007

So I want a column in table 1 that is the minimum date from table 2 that matches the PK and is >= the date in table 1.

It would return:
A 2/1/2006
B 2/1/2009
C 5/1/2007
D Err or NULL

I think that example kinda covers most of the possibilities here. If anyone has a good solution. Please help!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Ok, this has been killing me for a few days.
I have two tables
Number 1:
PK Date
A 1/1/2006
B 2/1/2009
C 3/1/2007
D 5/1/2007

Number 2:
PK Date
A 1/1/2005
A 2/1/2006
A 5/1/2009
B 2/1/2009
B 5/1/2010
C 5/1/2007
D 4/1/2007

So I want a column in table 1 that is the minimum date from table 2 that matches the PK and is >= the date in table 1.

It would return:
A 2/1/2006
B 2/1/2009
C 5/1/2007
D Err or NULL

I think that example kinda covers most of the possibilities here. If anyone has a good solution. Please help!
Let's assume table 1 is in the range A2:B5 and table 2 is in the range F2:G8.

Enter this array formula** in C2 and copy down as needed:

=IF(MIN(IF(F$2:F$8=A2,IF(G$2:G$8>=B2,G$2:G$8)))=0,"",MIN(IF(F$2:F$8=A2,IF(G$2:G$8>=B2,G$2:G$8))))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Format as Date.
 
Upvote 0
Let's assume table 1 is in the range A2:B5 and table 2 is in the range F2:G8.

Enter this array formula** in C2 and copy down as needed:

=IF(MIN(IF(F$2:F$8=A2,IF(G$2:G$8>=B2,G$2:G$8)))=0,"",MIN(IF(F$2:F$8=A2,IF(G$2:G$8>=B2,G$2:G$8))))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Format as Date.
Or, you could use the shorter array formula**:

=MIN(IF(F$2:F$8=A2,IF(G$2:G$8>=B2,G$2:G$8)))

And then use a custom cell format to suppress the display of 0:

m/d/yyyy;General;;

Note that if using this formatting cells will still contain numeric 0 you just won't see it. The cell will appear to be blank but it's not.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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