Index/Match with multiple criteria, but one is exact and other is largest without going over

mst3k4L

Board Regular
Joined
Nov 3, 2011
Messages
55
I have a table that looks like the one below with the dates sorted in descending order.

PersonDateNumber
Jose1/1/201498
Rosa5/14/1447
Jose6/1/143
Rosa2/1/15456
Jose12/5/153
Rosa5/2/16-10


I want to enter a name and date and have excel search the table for the exact name and the closest date without going over, and then provide the answer in the "Number" column. For example, entering "Rosa" and "6/2/14" will result in "47", while "Jose" and "6/2/14" will be "3".

I'm assuming it's some combination of Index & Match. Feel free to use something else, but please void VBA if possible. I can resort the table as needed. Thanks in advance!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

Assuming Names in column A, Dates in column B, Number in column C (Titles in row 1) + NameInput in E1 and DateInput in E2. Where you want the result:
Code:
=INDEX($A$2:$C$101, MATCH(MIN(IF($A$2:$A$101=$E$1,ABS($B$2:$B$101-$E$2))),
                          IF($A$2:$A$101=$E$1,ABS($B$2:$B$101-$E$2)),0), 3)
validate with Ctrl+Shift+Enter (array formula)

Regards
XLearner
 
Upvote 0
Hi,

Assuming Names in column A, Dates in column B, Number in column C (Titles in row 1) + NameInput in E1 and DateInput in E2. Where you want the result:
Code:
=INDEX($A$2:$C$101, MATCH(MIN(IF($A$2:$A$101=$E$1,ABS($B$2:$B$101-$E$2))),
                          IF($A$2:$A$101=$E$1,ABS($B$2:$B$101-$E$2)),0), 3)
validate with Ctrl+Shift+Enter (array formula)

Regards
XLearner
Thanks for the quick response. Unfortunately I ran into a problem. The code appears to be looking at the closest date in the array, regardless of if it is greater than or less the entered date. This is probably because of the MIN(ABS()) command which appears to be minimizing the absolute difference.
 
Upvote 0
Are you saying I misunderstood "the closest date"? Are you looking for the closest to TODAY?
 
Upvote 0
Are you saying I misunderstood "the closest date"? Are you looking for the closest to TODAY?
I need to closest date that matches the criteria in the array without the date being greater than the date in the array. So if a person enters "Rosa", they can enter any date from "5/14/14" to "1/31/15" and the result will be 47. This is because these dates are greater than or equal to 5/14/14, but less than 2/01/15. Does that help?
 
Upvote 0
Don't want to waste your time... I really don't get it. Read and re-read your last reply several times but I still don't get the idea. Sorry about that
 
Last edited:
Upvote 0
Could you try:
Code:
=INDEX($A$2:$C$101, MATCH(LARGE(($A$2:$A$101=$E$1)*($B$2:$B$101<=$E$2)*($B$2:$B$101),1),
                          ($A$2:$A$101=$E$1)*($B$2:$B$101<=$E$2)*($B$2:$B$101), 0), 3)
validate with Ctrl+Shift+Enter
 
Upvote 0
Don't want to waste your time... I really don't get it. Read and re-read your last reply several times but I still don't get the idea. Sorry about that
Sorry for my poor explanations, but what if I did it in code? Instead of only having 1 conditional statement (Person = "Rosa"), I need 2 conditional statements (Person = "Rosa" & Date >= the date next to Rosa). The below code doesn't work, but it illustrates what I am trying to accomplish. I underlined the conditional statements.

Code:
=INDEX($A$2:$C$101, MATCH(MIN(IF([U]AND($A$2:$A$101=$E$1,$E$2>=$B$2:$B$101)[/U],ABS($B$2:$B$101-$E$2))),
                          IF([U]AND($A$2:$A$101=$E$1,$E$2>=$B$2:$B$101)[/U],ABS($B$2:$B$101-$E$2)),0), 3)
 
Upvote 0
Could you try:
Code:
=INDEX($A$2:$C$101, MATCH(LARGE(($A$2:$A$101=$E$1)*($B$2:$B$101<=$E$2)*($B$2:$B$101),1),
                          ($A$2:$A$101=$E$1)*($B$2:$B$101<=$E$2)*($B$2:$B$101), 0), 3)
validate with Ctrl+Shift+Enter

This actually works! The only problem I am having is that sometimes the date entered is greater than any other date with that criteria, so it just grabs the first data point in the table. For example, entering "Jose" and "1/1/16" should give an answer of "3", but it instead gives "98" (first entry in table). Any thoughts?
 
Upvote 0

Forum statistics

Threads
1,218,220
Messages
6,141,231
Members
450,344
Latest member
renslaw

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