Lookup value on another sheet where in date range

BigRods

Board Regular
Joined
Dec 16, 2011
Messages
68
Hi,
Hoping someone could help: I have a list of patient No's and the dates of their stay. Patients could have multiple stays - if they are still here then the Deduction Date is blank.

I then have another dataset of drugs prescribed; using the Start Date of the drugs I'd like to identify which Stay the prescription was under

Data looks as follows - in the Drugs Prescribed table, the 1st row for patient 123456 needs to have "Stay No" as 3 because the Start Date is between the Registration Date and Deduction Date of the Stays table, the Lookup would need to ignore the first entry for patient 123456:

Stays

Patient IDRegistration DateDeduction DateStay No
12345610-Mar-2125-Mar-211
98765411-Mar-212
12345626-Jun-2115-Aug-213

Drugs Prescribed

Patient IDDrugStart DateStay No
123456Paracetamol28-Jun-213
987654Ibuprofen15-Mar-212

Many thanks for any help - would this be some kind of INDEX/MATCH formula? And could it deal with instances of the End Date being blank?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi BigRods,

The tricky bit was handling the empty dates for Decuction Date (hence the extra data row for testing) but I think this does what you ask.

BigRods.xlsx
ABCD
1Patient IDRegistration DateDeduction DateStay No
212345610-Mar-2125-Mar-211
398765411-Mar-2112-Mar-212
412345626-Jun-2115-Aug-213
598765411-Mar-214
6
Stays


BigRods.xlsx
ABCD
1Patient IDDrugStart DateStay No
2123456Paracetamol28-Jun-213
3987654Ibuprofen15-Mar-214
Drugs Prescribed
Cell Formulas
RangeFormula
D2:D3D2=IFERROR(IF(A2="","",INDEX(Stays!$D$2:$D$11,AGGREGATE(15,6,ROW(Stays!$A$2:$A$11)-ROW(Stays!$A$1)/((Stays!$A$2:$A$11=A2)*(C2>=Stays!$B$2:$B$11)*((Stays!$C$2:$C$11="")+(C2<=Stays!$C$2:$C$11))),1))),"No matching Stay")
 
Upvote 0
Solution
I haven't included all the error handling that Toadstool has but here are 2 other options.
The formula in D relies on the Stays list being in Ascending day order and it also won't tell you if scripts dates fall outside of stay dates.

20210920 Lookup MultiCriteria and Blank Date.xlsx
ABCDE
1Patient IDDrugStart DateStay No (Sorted Stay List)Stay No (Unsorted Stay List)
2123456Paracetamol28-Jun-2133
3987654Ibuprofen15-Mar-2122
4123456Paracetamol25-Mar-2111
5987654Ibuprofen28-Jun-2122
6
Drugs Prescribed
Cell Formulas
RangeFormula
D2:D5D2=LOOKUP(2,1/((Stays!$A$2:$A$5=$A2)*(Stays!$B$2:$B$5<=C2)),Stays!$D$2:$D$5)
E2:E5E2=LOOKUP(2,1/((Stays!$A$2:$A$5=$A2)*(Stays!$B$2:$B$5<=C2)*((Stays!$C$2:$C$5>=C2)+(Stays!$C$2:$C$5=""))),Stays!$D$2:$D$5)
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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