Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to get days and records between events?

I need to get number of days between two events and the number ofrecords between two events in Qlikview. The orginal data is as follow. I need to know the number of days between surgery infections and the number of records between infections. The summary table is attached to the data table. Is there any way to do it in Qlikview?

Thanks

PatientIDSurgeryDateInfection
110/21/2012Yes
210/22/2012No
310/23/2012No
410/24/2012No
510/25/2012No
610/26/2012No
710/27/2012No
810/28/2012No
910/29/2012No
1010/30/2012No
1110/31/2012No
1211/1/2012No
1311/2/2012Yes
1411/3/2012No
1511/4/2012No
1611/5/2012No
1711/6/2012No
1811/7/2012No
1911/8/2012No
2011/9/2012No
2111/10/2012No
2211/11/2012No
2311/12/2012Yes
2411/13/2012No
2511/14/2012No
2611/15/2012No
2711/16/2012No
2811/17/2012No
2911/18/2012No
3011/19/2012No
3111/20/2012No
3211/21/2012No
3311/22/2012No
3411/23/2012YES
3511/24/2012No
3611/25/2012No
3711/26/2012No

PatientIDSurgeryDateInfectionNumber of days between surgeriesNo. of surgeries between infection
110/21/2012Yes
1311/2/2012Yes
2311/12/2012Yes
3411/23/2012YES
1 Solution

Accepted Solutions
danielact
Partner - Creator III
Partner - Creator III

If each surgery gets a new PatientID, and they're always ordered by date, use this attachment. If they're not, that's simple enough to set up in your script, and use the new field instead of PatientID.

View solution in original post

8 Replies
hic
Former Employee
Former Employee

One way is

LOAD *,

     if(Infection='Yes',Peek(RecordCounter)+1) as RecordsSinceLastInfection,

     if(Infection='Yes',SurgeryDate - Peek(DateOfLastInfection) + 1) as DaysBetweenInfections;

LOAD *,

     if(Infection='Yes',SurgeryDate,Peek(DateOfLastInfection)) as DateOfLastInfection;

LOAD PatientID,

     Date#(SurgeryDate, 'MM/DD/YYYY') as SurgeryDate,

     Capitalize(Infection) as Infection,

     if(Capitalize(Infection)='Yes',0,Peek(RecordCounter)+1) as RecordCounter

FROM [Infections.xlsx] (ooxml, embedded labels, table is Sheet1);

HIC

Not applicable
Author

Is this possible to do the same thing at expression level? I would like o make it dynamic. If users are using filters, the number of days and the number of surgeries will change. By using set analysis, I can get surgery infection cases and use Above function to days between adjacent dates. But I do not know whether I can get numbers of records between adjacent dates.

Thank you very much.

hic
Former Employee
Former Employee

If you can solve the date problem using Set Analysis and the Above() function, you should be able to do the same with number of records. Use the RowNo() function to find the record number in the chart.

HIC

Not applicable
Author

Thank you for your suggestions. I can get number of days between adjacent dates on which surgery infection occurred, but I cannot get the number of records using RowNo() function. Please see the sample file in the attachment.

danielact
Partner - Creator III
Partner - Creator III

If each surgery gets a new PatientID, and they're always ordered by date, use this attachment. If they're not, that's simple enough to set up in your script, and use the new field instead of PatientID.

Not applicable
Author

It works as it should be. Thanks.

I do have two questions about your script.

1. You add all fields into Dimensions and add =if(Infection='Yes',1,null()) as a new dimension. It looks like it can be used to filter the data points on x-axis. Is this correct? I actually tried to use set analysis to limit the data points on x-axis to only the record whose infection is equal to 1. What is the logic here?

2. In two expressions you used, TOTAL key word is used. Why does the TOTAL do here?

3. Is there any way to hide the first data point since it is always 0?

Thanks again

danielact
Partner - Creator III
Partner - Creator III

For the first point, I think that set analysis works best when there's a calculation being performed, not just a simple "use only this value". You can combine the calculated dimension with the infection field instead - just switch the last dimension to =if(Infection='Yes',Infection,null()) and you can get rid of the first one (make sure you set it to supress null values!)

The TOTAL keyword is used so that the above function will work properly

I'm not sure about hiding the first row. I'm sure there's a way, I just can't think of it right now.

Not applicable
Author

Hello!

How make this work if my PatientID is not sequential?

I need to know a number of days between events, to  know which patients did a same event in  less seven days.