Skip to main content
Announcements
Qlik Community Office Hours - Bring your Ideation questions- May 15th, 11 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Group Patient IDs by Consecutive Date Ranges

In the table below patient 001 has consecutive date ranges in the first three rows, so that should count as a single hospital admission (for which I would calculate a single total Length of Stay (LOS)=41). Rows 4 and 5 should be counted as a separate admission (another two consecutive date ranges), total LOS = 20 days. Person 002 in the last row has only one date range, which is counted as one admission with a LOS of 8. 

ID

START

END

LOS

001

2016-08-24

2016-08-31

7

001

2016-09-01

2016-09-30

29

001

2016-10-01

2016-10-06

5

001

2016-12-03

2016-12-19

16

001

2016-12-20

2016-12-24

4

002

2016-02-12

2016-02-20

8

6 Replies
Gysbert_Wassenaar

Perhaps something like this:

tempTable:

LOAD

     ID,

     START,        

     END,

     LOS

FROM

     source_table

     ;

/* If START and END are text fields then first convert them to dates using the Date#() function:

    Date(Date#(START, 'YYYY-MM-DD'),'YYYY-MM-DD') as START,     */

Result:

LOAD

     *,

     AutoNumber([Admission START], ID) as [Admission Number]

     ;

LOAD

     *,

     If(START = Previous(END) + 1, Peek('Admission START'), START) as [Admission START]

     If(START = Previous(END) + 1, LOS + Peek('Running Admission LOS'), LOS) as [Running Admission LOS]    

RESIDENT

     tempTable

ORDER BY

     ID,

     START,

     END

     ;


talk is cheap, supply exceeds demand
Digvijay_Singh

May be this -

Capture.PNG

Digvijay_Singh

This is far better than I proposed! I think ID check would be needed along with START date comparison, am I missing something?

Not applicable
Author

Thank you! Currently working on implementing this.

Not applicable
Author

Thank you! I am currently trying to implement both proposed solutions.

MarcoWedel

Hi,

another solution might be:

QlikCommunity_Thread_259171_Pic1.JPG

QlikCommunity_Thread_259171_Pic2.JPG

QlikCommunity_Thread_259171_Pic3.JPG

QlikCommunity_Thread_259171_Pic7.JPG

table1:

LOAD ID,

    START,

    END,

    END-START as LOS,

    RecNo() as %Key

FROM [https://community.qlik.com/thread/259171] (html, codepage is 1252, embedded labels, table is @1);

Join

LOAD %Key,

    RangeSum(Peek(admID),-(ID<>Previous(ID) or START<>Previous(END)+1)) as admID

Resident table1

Order By ID, START;

hope this helps

regards

Marco