Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Best calculation of time difference when the data is in multiple rows of a table

Hello,

I'd like to get some advice on how best to calculate time difference when the data is in multiple rows of a table.

In the example below (POR to next PIR) is easy to calculate in Excel by setting the later PIR_TIME minus the earlier POR_TIME for the surgeon.

However, when I've tried to recreate this in Qlikview, I keep getting errors.

I've done something similar to this in SQL using a CTE but am not as well-versed as how to handle this dynamically in Qlikview - in the load script, functions, etc.

Welcome your responses!

Regards,

Karen

   

PROCEDURE_DATE_DTCASE_CONFIRMATION_NUMSURGEONPIR_TIMEPOR_TIMEPOR to next PIR
07/20/20151Dr. B07:3609:36
07/20/20152Dr. B09:5913:2023
07/20/20153Dr. B13:0515:00-15
07/20/20154Dr. B14:4016:14-20
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi Wallace,

Try below solution:

Data:

load * inline

[

PROCEDURE_DATE_DT,PIR_TIME,POR_TIME 

07/20/2015,07:15,08:03

07/20/2015,07:36,09:36

07/20/2015,09:11,10:17

07/20/2015,09:59,13:20

07/20/2015,13:05,15:00

07/20/2015,14:40,16:14

07/20/2015,16:16,18:11

];

LOAD *,

if(PROCEDURE_DATE_DT = Peek(PROCEDURE_DATE_DT ),  Interval(PIR_TIME-Previous(POR_TIME) ,'')) as TimeBetweentransactions

Resident Data;

Timediff.png

hope it helps!

Regards

Neetha

View solution in original post

12 Replies
Anonymous
Not applicable
Author

take min(PIR_TIME) max(POR_TIME) and calculate the time duratiion

lironbaram
Partner - Master III
Partner - Master III

hi

if you want to calculate it at the script level

you can use

Load *

      if(previous(Surgeon)=Surgeon,PIR_TIME-previous(POR_TIME) ) As POR to next PIR

Resident XXXX

ORDER BY SURGEON ,PROCUDRE_DATE_DT ,CASE_CONFIRMATION_NUM

Not applicable
Author

Neeti and Liron,

Thank you very much for your feedback.

I tried both of your suggestions (per below) but am still not getting the correct time (in the Test TOT Actual column):

   

PROCEDURE_DATE_DTPIR_TIMEPOR_TIMETest TOT neethaTest TOT lironTest TOT Actual
07/20/201507:1508:03-182-48
07/20/201507:3609:36-518-120-27
07/20/201509:1110:17-349-66-25
07/20/201509:5913:2023-201-18
07/20/201513:0515:00-306-115-15
07/20/201514:4016:14--94-20
07/20/201516:1618:11--1152
Anonymous
Not applicable
Author

hi wallace,

what are the values in Test TOT Actual column.

are they mins ?

Anonymous
Not applicable
Author

how did you arrive the result for the column

Not applicable
Author

For the first case of the day, there is not calculation.

For the [Test TOT Actual] second case of the day, I start at row 2 and subtract PIR_TIME 7:36 from POR_TIME in row 1 which is 8:03.

This continues for each of the cases in sequential order.

It may appear odd that the cases look like they overlap - in some cases, one physician is doing multiple procedures at one time.

I've done a recursive technique in SQL before to address this; however, am not sure how to "loop" through in Qlik.

Appreciate your help!

maxgro
MVP
MVP

I think Liron already suggested a possible answer

Another could be (if CASE_CONF.... are progressive values) a join of the table with the same table (same surgeon, procedure_date, CASE_CONF = CASE_CONF +1) so you have pir_time and previuos row por_time on the same row

If you can post some data, qvd or excel or qvw...........

Anonymous
Not applicable
Author

Hi Wallace,

Try below solution:

Data:

load * inline

[

PROCEDURE_DATE_DT,PIR_TIME,POR_TIME 

07/20/2015,07:15,08:03

07/20/2015,07:36,09:36

07/20/2015,09:11,10:17

07/20/2015,09:59,13:20

07/20/2015,13:05,15:00

07/20/2015,14:40,16:14

07/20/2015,16:16,18:11

];

LOAD *,

if(PROCEDURE_DATE_DT = Peek(PROCEDURE_DATE_DT ),  Interval(PIR_TIME-Previous(POR_TIME) ,'')) as TimeBetweentransactions

Resident Data;

Timediff.png

hope it helps!

Regards

Neetha

Not applicable
Author

Hi Neetha,

This is a great suggestion - thank you!

I just need to clean up some synthetic keys that are being generated!

Much appreciation!