+ Reply to Thread
Results 1 to 13 of 13

conditional vlookup to find entry within date range

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    conditional vlookup to find entry within date range

    Hi, I have a list of operation details and admission details where the patient number is the unique identifier. I want to use vlookup to find the operation that matches the admission - that is, the operation date occured between the admission and discharge dates.

    There can be multiple admissions for one patient, but I only want the one with the operation. When I use plain old vlookup I get the first admission in the list... so what I want to know is how can I vlookup based on a date range criteria? eg, if op date > adm date and < dis date

    Thanks in advance!

    Ruth

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: conditional vlookup to find entry within date range

    Something like this maybe?

    =INDEX($D$2:$D$100,MATCH(1,INDEX(($A$2:$A$100="X")*($B$2:$B$100>=DATE(year,month,day))*($B$2:$B$100<=DATE(year2,month2,day2)),0),0))

    Where D2:D100 is the range of values to return if match found. A2:A100 is range to match for patient, B2:B100 is range with dates to match against start and end dates .

    Adjust as necessary. This finds first row with patient id match and with date with start/end dates identified.

    Note: You can replace "X", DATE(year,month,day) and DATE(year2,month2,day2) with cell references containing match criteria.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: conditional vlookup to find entry within date range

    that looks good, and thank you, but I'm having trouble applying it to my sample data - would you mind showing me how it fits in the attached?
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: conditional vlookup to find entry within date range

    Is this what you're looking for?
    Attached Files Attached Files
    -Greg If this is helpful, pls click Star icon in lower left corner

  5. #5
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: conditional vlookup to find entry within date range

    Sorry...made a quick change. This one should be better.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: conditional vlookup to find entry within date range

    whoops, just had a closer look... i wanted to change the date to date time, I made a new operation date time of a few minutes after the admission date time - it worked but I had another look at the formula and noticed that the range in the vlookups wasn't static - when I moved the op data around it stopped working for a couple of admission entries. I tried to anchor the range with the whole $ thing, but then it didn't work for some that it should when I copied the formula down the row... any clues?
    Last edited by coffee_man; 08-06-2011 at 04:07 AM. Reason: more info

  7. #7
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: conditional vlookup to find entry within date range

    Sorry about that! Just me being a little lazy replace the formula with this:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: conditional vlookup to find entry within date range

    thanks for that - except it still isn't picking up the operation with a date time of a few minutes after admission. it is possible that I could encounter that scenario in my data. the weird thing is, I made my new operation time (2 minutes after admision) and it worked straight away - then I noticed the range in the vlookup was different. when I anchored it, it stopped working...

  9. #9
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: conditional vlookup to find entry within date range

    Could you repost an example workbook with the time included? Thanks!

  10. #10
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: conditional vlookup to find entry within date range

    here 'tis, ta
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: conditional vlookup to find entry within date range

    So I think this will fix the issue, but under the condition that two operations don't happen during the same Admission period. I added the COUNTIFS function as a way to force an error if there is no operation as well as if there are more than one in the same Adm. period. Also I put in a conditional format to display the instances where there are multiple Op dates in an Adm. period.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: conditional vlookup to find entry within date range

    or perhaps:

    Please Login or Register  to view this content.
    copied down after adjusting ranges to suit.

  13. #13
    Registered User
    Join Date
    08-16-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: conditional vlookup to find entry within date range

    thank you both, I'll give them a spin with my many thousands of rows and see how it goes!
    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1