8 Replies Latest reply on Nov 27, 2018 12:12 PM by Matt Huff Branched to a new discussion.

# Difference in date from different rows

I am trying to create a calculation that shows the difference in days from when one patient admits/discharges to the next time they admit.  In the screenshot, you can see a patient has two different visitIDs with one medical record number.  I want to find the difference from the discharge date of the first visit to the admit date of the second visit.  (All personal information has been changed).  If they have 3 or more visits I would want to continue calculating the time in between each visit from discharge to admit.

Thanks in advance!

• ###### 1. Re: Difference in date from different rows

Hi Matt,

Can you attach a workbook? Or mock data?

Thx, Don

• ###### 2. Re: Difference in date from different rows

Sample Data attached

• ###### 3. Re: Difference in date from different rows

Hi Matt,

Find my approach based on lookup function as reference below and stored in attached workbook version 2018.2 located in the original thread.

1. M1. lookup Discharge Date: lookup(attr([Discharge Date]),-1)

2. M2. Lookup Medical Rec: lookup(attr([Medical Rec]),-1)

3. M3. Delta: if attr([Medical Rec])=[M2. Lookup Medical Rec] then datediff('day', [M1. lookup Discharge Date],attr([Admit Date])) END

4. Drag the required objects to the indicated locations and hide M2. Lookup Medical Record.

Hope it helps.

Regards,

Norbert

• ###### 4. Re: Difference in date from different rows

Hi Matt,

I just downloaded the data but the schema is not exactly the same as displayed in your original post?

Regardless, the attached 2018.3 workbook and below screenshot should help you along. If yes, please mark this response as correct. Thx! Don

1 of 1 people found this helpful
• ###### 5. Re: Difference in date from different rows

Hey Don,

Super efficient coding! Just for me or did i overlook something;) . Why should you set 0 for the last record of the pane?

Regards,

Norbert

2 of 2 people found this helpful
• ###### 6. Re: Difference in date from different rows

Hi Norbert,

Good catch! That LAST() shouldn't be there!

Still recovering from too much tryptophan me thinks.

Thanks !  D

• ###### 7. Re: Difference in date from different rows

Thanks so much!

• ###### 8. Re: Difference in date from different rows

Hey Matt,

I know you marked my response as correct, but could you give Norbert a "This helped me' click too? He caught my error   so he deserves a nod!

Thx , Don