Nearest date based on three criteria

chris_bosten

New Member
Joined
Aug 21, 2024
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have 3 criteria: Vehicle, Model and Year

In the first table I have a date "Date 1"

In the second table I have a different date "Date 2"

Vehicle (A)Model (B)Year (C)Date1 (D)New Date (E)(F)Vehicle (G)Model (H)Year (I)Date2 (J)
FordMondeo
1992​
16/08/2024​
17/08/2024
FordMondeo
1992​
17/08/2024​
#N/A​
VauxhallLeo
1993​
19/08/2024​
FordEscort
1995​
15/08/2024​

I want "New Date" to return the date in Date 2 that is closest to date 1 when vehicle, model and year are matched in the two tables.

Based on an old thread I have a formula that works in E2 for one criteria, vehicle alone:

=INDEX(J3:J5,MATCH(MIN(IF(G3:G5=A3,IF(J3:J5<>D3,ABS(J3:J5-D3)))),IF(G3:G5=A3,IF(J3:J5<>D3,ABS(J3:J5-D3))),0))

However, I have tried an IF(AND logic to add an additional criteria (Model), but I get an #NA result:

=INDEX(J3:J5,MATCH(MIN(IF(AND(G3:G5=A3,H3:H5=B3),IF(J3:J5<>D3,ABS(J3:J5-D3)))),IF(AND(G3:G5=A3,H3:H5=B3),IF(J3:J5<>D3,ABS(J3:J5-D3))),0))

What am I doing wrong?

Best wishes
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello, with 365 and presuming that "closest" means in both directions you could e.g. use:

Excel Formula:
=LET(
a,FILTER(J3:J7,(G3:G7=A3)*(H3:H7=B3)*(I3:I7=C3)),
b,ABS(a-D3),
UNIQUE(FILTER(a,b=MIN(b))))
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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