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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

calculating time differences

I need to calculate the time differences between the dispensing of any two subsequent prescriptions.  The following table illustrates the situation:

   

ScriptNumberDateTImeDispensed
16179730/01/15 18:29
16179830/01/15 18:45
16179830/01/15 18:45
16179830/01/15 18:45
16179930/01/15 18:49
16180031/01/15 08:18
16180031/01/15 08:18
16180131/01/15 08:39
16507327/03/15 07:44
16180231/01/15 09:14
16180331/01/15 09:38
16180431/01/15 09:41
16180431/01/15 09:41
16180431/01/15 09:41
16180531/01/15 09:48
16180631/01/15 09:55
16180631/01/15 09:55
16180631/01/15 09:55
16180731/01/15 10:03
16180831/01/15 10:19
16180931/01/15 10:21
16181031/01/15 10:22
16181031/01/15 10:22
16181131/01/15 10:28
161811

31/01/15 10:28

The ScriptNumber is a unique identifier of a prescription.  How do i calculate the time difference between any two prescriptions?

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

Try changing the expression to:

Dispensed-Above(Dispensed)

View solution in original post

13 Replies
maxgro
MVP
MVP

ab:

LOAD ScriptNumber,

     DateTImeDispensed

FROM

[https://community.qlik.com/thread/160619]

(html, codepage is 1252, embedded labels, table is @1);

tmp:

NoConcatenate load distinct

  ScriptNumber, DateTImeDispensed

Resident ab;

ac:

load *,

  time(timestamp#(DateTImeDispensed,'DD/MM/YYY hh:mm')- Timestamp#(Peek(DateTImeDispensed),'DD/MM/YYY hh:mm')) as Delta

Resident tmp

order by ScriptNumber;

DROP Table tmp, ab;

Anonymous
Not applicable
Author

Many thanks Massimo.  I am getting the following error message:

Screen Shot 2015-04-18 at 00.12.02.png

maxgro
MVP
MVP

my .qvw run without error (PFA)

maybe you have to change the "resident ab" if your table has a different name

petter
Partner - Champion III
Partner - Champion III

An alternative is to keep your data as it is in your data model and then just use a Straight Table and do the calculation there like this - see also attached QVW:

2015-04-18 #1.PNG

Anonymous
Not applicable
Author

Many thanks Petter for the alternative.  My results are as follows:

Screen Shot 2015-04-18 at 01.25.02.png

i get blanks in the columns.  Is it because of the datetime format?  How can this be resolved?

Anonymous
Not applicable
Author

Many thanks, ran without error but get the following results:

Screen Shot 2015-04-18 at 01.34.42.png

What could be the problem?

petter
Partner - Champion III
Partner - Champion III

Could be - is it possible for you to upload a sample of your appllication or share a spreadsheet with a bit of the data?

petter
Partner - Champion III
Partner - Champion III

Try changing the expression to:

Dispensed-Above(Dispensed)

maxgro
MVP
MVP

in your first post same script number has same date

in the second same script  number has different date and the datetime format changed

better if you can add an extract of your qlikview .qvw

if you want to do the diff in script, use (adapt) my solution

if you want in chart, Petter has already answered (above function), you just have to pay attention to date time format