+ Reply to Thread
Results 1 to 9 of 9

Calculate how many days patients have had medication in year (excluding overlapping dates)

  1. #1
    Registered User
    Join Date
    02-21-2018
    Location
    Sweden
    MS-Off Ver
    2016
    Posts
    3

    Calculate how many days patients have had medication in year (excluding overlapping dates)

    Hi,

    I have tried to solve this problem by modifying similar codes I found from this forum but so far without success. I need to calculate the time each patient (A1=Patient id) have had medication in each year 2011-2017. Unfortunately the data is not perfect and there are overlapping dates (even though there should not be) and quite many cases are missing the end date.

    It is not possible for me to know for sure if the missing end date is there on purpose (=the medication is on) or if they forgot to enter the end date to the medical records. For now, I will assume that the mediation is still on if there is no end date and new mediation phase has not been started for the patient. Additionally, the last medication phase should end at time the person dies (D1=Time of death).

    I have managed to calculate the time in days for each year (2011_days_sum, 2012_sum, etc.), but the overlapping dates were causing issues. I have manually fixed this sample data to look somewhat how it should look, though there may be mistakes.


    Best regards

    Teppo
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    Wrong result. Removed by GK.
    Last edited by Glenn Kennedy; 02-26-2018 at 10:04 AM.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    Attempt 2. A bit of a monster, but it seems to deliver what you want.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    02-21-2018
    Location
    Sweden
    MS-Off Ver
    2016
    Posts
    3

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    This looks very promising. I will test it with the real data to see how it works. Thank you very much so far!

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    Note that the year headers are dates, (1st January) formatted as "yyyy"....

  6. #6
    Registered User
    Join Date
    02-21-2018
    Location
    Sweden
    MS-Off Ver
    2016
    Posts
    3

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    I tested the code in my data and it works most of the time quite nicely. The sample data in my first post was a bit small and not very well chosen. It seems there are some strange results there with original data. For example, days for patient id 570 (now added to the sample data) did not calculate correctly. I tried to read the “monster code”, but so far, I have not figured out what is wrong. (Could be a user error as well?)

    Another issue is the remaining overlapping dates.
    In the original sample data I had also the sums of days per patient, (2011_days_sum etc.), because I need to know how many days a patient has had the medication in each year and I can’t just sum up the days as the dates are sometimes overlapping. Earlier I tried to calculate just the number of overlapping dates and subtract it from the aggregated sum, but failed with that.

    Thank you so far for the help and very quick response. I really appreciate it.
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    "For example, days for patient id 570 (now added to the sample data) did not calculate correctly"... and you expected ????

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    Ah. I see now. You have fundamentally changed things, haven't you. Previously one could have died, had medication stop or continue being treated. now you can cease medication and subsequently die....

    Easy enough to fix. I'll not be able to do it now, though. look back in the UK morning.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: Calculate how many days patients have had medication in year (excluding overlapping da

    Try it now...
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calculate days excluding some days between dates
    By sam16 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-06-2017, 02:35 PM
  2. Calculate how many days in a year that falls between two dates
    By shaunguyver in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-13-2016, 08:12 AM
  3. Calculate days using DateTime Picker excluding weekends and dispaly dates column wise
    By bhuvana86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2015, 02:10 PM
  4. Replies: 7
    Last Post: 06-19-2013, 05:45 AM
  5. Replies: 0
    Last Post: 02-01-2013, 05:10 PM
  6. Replies: 4
    Last Post: 12-01-2012, 09:37 AM
  7. [SOLVED] formula to calculate # of days between dates, excluding holidays
    By abs2299 in forum Excel General
    Replies: 9
    Last Post: 10-11-2012, 03:59 AM

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