Index/Match Array to find closest date/time AND match secondary criteria

seans81

New Member
Joined
May 14, 2020
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I want to start by saying I am using ctr + shift + enter.

I have a workbook with 2 worksheets. The first workbook has dates in column A, company name in column H

The second worksheet is called "Reference' and it has company name in column B, product in column C, and most recent order date in column G

I'm trying to match the date in sheet 1 to the closest date in sheet 2 for each company and return the prodcut they ordered from column C. I wrote an index match function to try and accomplish this but I'm getting an error "Did not find value '0' evaluation.

The formula:

=INDEX(Reference!$C$2:$C$70,

MATCH(MIN(IF(ISNUMBER(SEARCH($H906,Reference!$B$2:$B$70)),ABS($A906-$G$2:$G$17))),

IF(ISNUMBER(SEARCH($H906,Reference!$B$2:$B$70)),ABS($A906-$G$2:$G$17)),0))

Any help?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Sorry, fixed my code with the array issue, the one i posted above is an older version.

=INDEX(Reference!$C$2:$C$70,

MATCH(MIN(IF(ISNUMBER(SEARCH($H906,Reference!$B$2:$B$70)),ABS($A906-$G$2:$G$70))),

IF(ISNUMBER(SEARCH($H906,Reference!$B$2:$B$70)),ABS($A906-$G$2:$G$70)),0))
 
Upvote 0
Best suggestion that I can provide without a visual example would be

=IFERROR(LOOKUP($A906,Reference!$G$2:$G$70/(Reference!$B$2:$B$70=$H906),Reference!$C$2:$C$70),"No match")

You don't need to you use ctrl shift enter with this formula.
 
Upvote 0
Thanks for the response but this just goes to the error handler for all rows.

I tried to visualize it the best I can below. I need to populate column C in table 1 by using the company name and date from table 1.

Company name must match table 2 and the date must be the closest to date from table 1 without going over. Right now I am using an absolute function to subtract the 2 dates and see which is closer, but since company 1 shows up twice in table 2 and the absolute value of the 2 dates subtracted for row 2 is closer than the abs value of row 1, the formula would return 'stamps' instead of 'sprockets'

=ArrayFormula(INDEX(Reference!$C$2:$C$70,MATCH(MIN(IF($H2=Reference!$B$2:$B$70,abs($A2-Reference!$G$2:$G$70))),IF($H2=Reference!$B$2:$B$70,abs($A2-Reference!$G$2:$G$70)),0)))

ABC
1DateCompany NameProduct
205/11/2020Company 1Sprockets
305/12/2020Company 2

ABC
1CompanyProductOrder Date
2Company 1Sprockets5/08/2020
3Company 1Stamps5/12/2020
4Company 2Stamps5/9/2020
 
Upvote 0
I thought that I read that you wanted closest without going over.

There is another fairly recent question on the forum where the closest match either way was needed, I'll see if I can find it.

edit:- found it and don't think that the solutions we used there will be of any use here so I'll start looking at other ways.
 
Last edited:
Upvote 0
Is your user profile showing the correct version of excel? There are functions in newer versions which will make the task significantly easier.
 
Upvote 0
Yes - but I my have access to newer version. What is the function?
 
Upvote 0
I was thinking MAXIFS and MINIFS, but may have found a way to do it without.
 
Upvote 0
I've done this on a single sheet for testing, but it will work the same on 2 sheets. Should work in excel 2010 or newer.

In the event of a tie (multiple entries on the closest date, or entries an equal number of days before and after) the formula will return the match closest to the top of the list.
Book1
ABCDEF
1CompanyProductOrder Date
2Company 1Sprockets08/05/2020
3Company 1Stamps12/05/2020
4Company 2Stamps09/05/2020
5
6DateCompany NameProduct
711/05/2020Company 1Stamps
812/05/2020Company 2
Sheet15
Cell Formulas
RangeFormula
F7F7=INDEX(B:B,AGGREGATE(15,6,ROW($B$2:$B$4)/($A$2:$A$4=E7)/($C$2:$C$4=(D7+AGGREGATE(15,6,ABS($C$2:$C$4-D7)/($A$2:$A$4=E7),1)*{-1,1})),1))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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