Matching closest date with two sets of data

strevs

New Member
Joined
Mar 13, 2018
Messages
2
Hi Excel Wizards,

I'd really appreciate your help with this one.

I have two sets of data, the first has a list of PersonIDs and referral dates, the second has a list of IDs with assessment dates. The assessment can take place before, on the same day or after the referral date. The PersonIDs can appear multiple times with different referral and assessment dates.

I'd like to be able to match the nearest assessment date to the referral date for each Person ID.

I've been able to work it out for assessment dates on or before using MAX(IF and an array formula looking at dates equal to or before the referral date (see below), but it doesn't work when I change it to MIN(IF and an array formula looking at assessment dates equal to or after the referral date.

=MAX(IF(IF(PersonIDRange=PersonID,AssessmentDates,"")<=ReferralDate,AssessmentDates,"")))

Any help around this would be hugely welcomed.

Thanks,

Chris
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
how about something like:

=MIN(IF(ABS(IF(PersonIDRange=PersonID,AssessmentDates,date(9999,1,1))-ReferralDate)=MIN(ABS(IF(PersonIDRange=PersonID,AssessmentDates,date(9999,1,1))-ReferralDate)),AssessmentDates,date(9999,1,1)))

I hope I've not made mistakes but general idea is to build a set with time difference between (assesmentdates or 99/01/01(if wrong person) ) and referral dates.
Then each element of this set is compared to minimum of this set.
If it is smallest one, then AssesmentDAte is returned if not 99/01/01 .
And finally smallest element (the oldest assesment date with close referral date) will be selected
 
Upvote 0
how about something like:

=MIN(IF(ABS(IF(PersonIDRange=PersonID,AssessmentDates,date(9999,1,1))-ReferralDate)=MIN(ABS(IF(PersonIDRange=PersonID,AssessmentDates,date(9999,1,1))-ReferralDate)),AssessmentDates,date(9999,1,1)))

I hope I've not made mistakes but general idea is to build a set with time difference between (assesmentdates or 99/01/01(if wrong person) ) and referral dates.
Then each element of this set is compared to minimum of this set.
If it is smallest one, then AssesmentDAte is returned if not 99/01/01 .
And finally smallest element (the oldest assesment date with close referral date) will be selected

Thanks Kaper - this is very helpful.

Chris
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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