Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to subtract Begin Time - "Previous" End Time to determine gaps in between phone calls

I am trying to create a calculation that will Subtract Begin Time from the previous End Time to determine what the gap is between each call. However, I can't seem to get this to work correctly in QlikView. Any suggestions? Below is a data example. I would need to do this per person, per day.

NameDateBegin TimeEnd TimeGaps
Joe Smith9/10/107:49:497:50:07
Joe Smith9/10/108:09:178:13:21
Joe Smith9/10/108:24:478:25:15
Joe Smith9/10/108:25:418:30:38
Joe Smith9/10/108:31:458:32:37
Joe Smith9/10/108:32:598:33:29
Joe Smith9/10/108:33:378:34:20
Joe Smith9/10/108:34:308:39:26
Joe Smith9/10/108:42:518:43:58
Joe Smith9/10/108:44:238:45:06
Joe Smith9/10/108:45:368:49:55
Joe Smith9/10/108:51:278:52:28
Joe Smith9/10/109:48:179:48:35
Joe Smith9/10/1010:43:5510:45:17


6 Replies
johnw
Champion III
Champion III

Assuming you want to do it during the load instead of in the chart, and that you're sorting in Name then Date order, maybe this?

if(Name=previous(Name) and Date=previous(Date),interval("Begin Time"-previous("End Time"))) as Gap

Not applicable
Author

Thanks for your quick response and example. I used your example and put it in the script as:

if([Lead Dev Rep]=previous([Lead Dev Rep]) and Date=previous(Date),interval([Begin Time]-previous([End Time]))) as Gap,

It is partially working. I would expect to see the dash in the first line since there is not a 'previous' End Time but I get blanks throughout the rest of the column. Is there a way to have it work down the whole column and not have the '-' appear? Thanks for your help.

Lead Dev Rep

Date

Begin Time

End Time

Gap

Nbr of Calls

Duration per Call

70

Joe Smith

9/9/2010

7:25:36

7:25:50

-

1

0 :00:14

Joe Smith

9/9/2010

7:30:35

7:36:36

0:04:45

1

0 :06:01

Joe Smith

9/9/2010

7:48:02

7:49:38

0:11:26

1

0 :01:36

Joe Smith

9/9/2010

7:51:57

7:55:01

-

1

0 :03:04

Joe Smith

9/9/2010

7:56:05

7:56:10

-

1

0 :00:05

Joe Smith

9/9/2010

7:56:06

7:56:10

0:00:04

1

0 :00:04

Joe Smith

9/9/2010

7:56:21

7:56:27

0:00:11

1

0 :00:06

Joe Smith

9/9/2010

7:56:55

7:57:18

-

1

0 :00:23

Joe Smith

9/9/2010

7:57:53

7:59:00

-

1

0 :01:07

Joe Smith

9/9/2010

7:59:05

7:59:34

0:00:05

1

0 :00:29

Joe Smith

9/9/2010

8:02:41

8:13:27

-

1

0 :10:46

Joe Smith

9/9/2010

8:14:51

8:16:00

0:01:24

1

0 :01:09

Joe Smith

9/9/2010

8:16:44

8:17:25

-

1

0 :00:41

Joe Smith

9/9/2010

8:18:21

8:19:58

0:00:56

1

0 :01:37

Joe Smith

9/9/2010

8:20:41

8:21:23

0:00:43

1

0 :00:42

Joe Smith

9/9/2010

8:22:22

8:23:22

-

1

0 :01:00

Joe Smith

9/9/2010

8:24:27

8:25:38

-

1

0 :01:11

Joe Smith

9/9/2010

8:27:49

8:28:11

0:02:11

1

0 :00:22

Joe Smith

9/9/2010

8:28:22

8:28:45

-

1

0 :00:23

Joe Smith

9/9/2010

8:39:25

8:43:13

-

1

0 :03:48

Joe Smith

9/9/2010

9:03:21

9:06:27

-

1

0 :03:06

Joe Smith

9/9/2010

9:36:34

9:36:47

-

1

0 :00:13

johnw
Champion III
Champion III

Works fine for me. See attached. Are you "sorting in Name then Date order" like I mentioned? And actually, Begin Time should be there too, so sorting in Name, Date and Begin Time order?

Not applicable
Author

That was it. I was only sorting in QV and not in my Extract. I sorted my Excel file first as you mentioned and then loaded it. That worked! Thanks so much!

johnw
Champion III
Champion III


meganm wrote:That was it. I was only sorting in QV and not in my Extract. I sorted my Excel file first as you mentioned and then loaded it. That worked! Thanks so much!


Well, if it's acceptable to change the Excel file, then I guess that works. Generally speaking, I prefer to not change my source data to conform to QlikView, but rather change QlikView to conform to my source data. So another option, if sorting when reading from Excel doesn't work, would be to read in the file and then do a left join with the gap information:

LEFT JOIN (MyTable)
LOAD
UniqueKeyToMyTable
,if([Lead Dev Rep]=previous([Lead Dev Rep]) and Date=previous(Date),interval([Begin Time]-previous([End Time]))) as Gap
RESIDENT MyTable
ORDER BY [Lead Dev Rep], Date, [Begin Time]
;

See attached. Either way works, of course, so whatever you prefer is good.

Not applicable
Author

thanks for the tip. Makes sense