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: 
villegasi03
Creator
Creator

Difference in Timestamps Based On Previous Record's Timestamp

QV Community,

Sorry for the title of the post, I couldn't think of any other way to put it. I am sure this will be a simple question to answer but I am stumped. I am working with customer call data as shown in the table below. Nothing fancy. Just info on when the customer called us. How would you calculate the elapsed time since the previous call made by the customer. I attempted to use the previous function but it did nothing for me. I kept getting bad results because the calculations would not stay within distinct customer IDs. Any assistance with this would be very much appreciated. Thank you.

CALLAUTOHASHIDCALLDATECALLTIMECUSTOMERIDCALLDATETIMEElapsedTimeSinceLastCall
301/03/20127:08 AM1112222201/03/2012 7:08 AM?
67701/03/20129:53 AM1112222201/03/2012 9:53 AM?
74701/03/201210:04 AM1112222201/03/2012 10:04 AM?
1053501/04/20126:10 PM1112222201/04/2012 6:10 PM?
1536101/05/20125:47 PM1112222201/05/2012 5:47 PM?
9383401/26/20124:23 PM1115555501/26/2012 4:23 PM?
9383401/26/20124:23 PM1115555501/26/2012 4:23 PM?
9390001/26/20124:30 PM1115555501/26/2012 4:30 PM?
20220002/27/20127:27 PM1115555502/27/2012 7:27 PM?
26294403/16/20129:19 AM1115555503/16/2012 9:19 AM?
1 Solution

Accepted Solutions
fosuzuki
Partner - Specialist III
Partner - Specialist III

Hi,

Maybe you could make your load statement like this:

LOAD CALLAUTOHASHID,

          CALLDATE,

          CALLTIME,

          CUSTOMERID,

          CALLDATETIME,

          IF(PEEK('CUSTOMERID')=CUSTOMERID, CALLDATETIME - PEEK('CALLDATETIME')) AS ELAPSEDTIMESINCELASTCALL

FROM XXXXX

ORDER BY CUSTOMERID, CALLDATETIME;

The idea is to use the peek() function to use the previous' record information.

Hope this helps you

Fernando

View solution in original post

2 Replies
fosuzuki
Partner - Specialist III
Partner - Specialist III

Hi,

Maybe you could make your load statement like this:

LOAD CALLAUTOHASHID,

          CALLDATE,

          CALLTIME,

          CUSTOMERID,

          CALLDATETIME,

          IF(PEEK('CUSTOMERID')=CUSTOMERID, CALLDATETIME - PEEK('CALLDATETIME')) AS ELAPSEDTIMESINCELASTCALL

FROM XXXXX

ORDER BY CUSTOMERID, CALLDATETIME;

The idea is to use the peek() function to use the previous' record information.

Hope this helps you

Fernando

villegasi03
Creator
Creator
Author

This worked perfectly! Thank you Fernando!