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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
galileumax
Contributor II
Contributor II

Conditional counter

Hello to All,

I need your help to solve the following problem:

Input table is as follows:

    

IDNameDateStop
1Paperone03/01/2018 18:35
2Paperone20/01/2018 09:44
3Paperone23/04/2018 22:48Stop
4Paperone24/04/2018 11:57
5Paperone29/04/2018 16:28
6Paperone29/04/2018 16:30Stop
7Paperone30/04/2018 23:18
8Paperone02/05/2018 14:28
9Paperone24/07/2018 14:33
10Pippo04/01/2018 15:51
11Pippo02/08/2018 13:58Stop
12Pippo05/08/2018 11:00
13Pippo05/08/2018 11:01
14Pippo06/08/2018 23:26
15Topolino02/01/2018 13:04
16Topolino02/01/2018 15:46
17Topolino10/01/2018 09:40Stop
18Topolino11/01/2018 10:39
19Topolino12/01/2018 10:39
20Topolino15/01/2018 16:17
21Topolino20/01/2018 18:10

When in correspondence of a name there is a "stop"  the count begins

and if the difference between the date of the successive records for the same "Name" is less than 3 then "OK"

Perhaps the desired output is clearer:

      

IDNameDateStopDeltaOutput
1Paperone03/01/2018 18:35
2Paperone20/01/2018 09:44
3Paperone23/04/2018 22:48Stop
4Paperone24/04/2018 11:57 0,5Ok
5Paperone29/04/2018 16:28 5,7
6Paperone29/04/2018 16:30Stop5,7
7Paperone30/04/2018 23:18 1,3Ok
8Paperone02/05/2018 14:28 2,9Ok
9Paperone24/07/2018 14:33 85,9
10Pippo04/01/2018 15:51
11Pippo02/08/2018 13:58Stop
12Pippo05/08/2018 11:00 2,9Ok
13Pippo05/08/2018 11:01 2,9Ok
14Pippo06/08/2018 23:26 4,4
15Topolino02/01/2018 13:04
16Topolino02/01/2018 15:46
17Topolino10/01/2018 09:40Stop
18Topolino11/01/2018 10:39 1,0Ok
19Topolino12/01/2018 10:39 2,0Ok
20Topolino15/01/2018 16:17 5,3
21Topolino20/01/2018 18:10 10,4

Thanks in advance

Massimo

2 Replies
rubenmarin

Hi Massimo, maybe with:

LOAD Stop,

     If(Stop<>'Stop', Peek(Delta)+Date-Peek(Date)) as Delta,

If(Stop='Stop', '',

  If(Peek(Stop)='Stop',

    If(Delta<3, 'Ok',''),

    If(Delta<Peek(Delta)+3, 'Ok','')

)) as Output

MindaugasBacius
Partner - Specialist III
Partner - Specialist III

Try this script:

tmp:

LOAD ID,

    Name,

    Date#(Date, 'DD/MM/YYYY hh:mm') as Date,

    Stop

FROM

(ooxml, embedded labels, table is Sheet1);

NoConcatenate

tmp2:

LOAD *

Resident tmp

Order by Name asc, Date asc

;

DROP Table tmp;

NoConcatenate

tmp:

LOAD ID

,Name

,Date

,If(Peek(Name) = Name and Len(Trim(Stop)) = 0, Peek(Stop), Stop) as Stop

Resident tmp2;

DROP Table tmp2;

NoConcatenate

tmp2:

LOAD *

,If(Peek(Stop) = 'Stop' and Peek(Name) = Name,

If(Date - Peek(Date) < 3, 'OK', Null())) as Trigger

,If(Peek(Stop) = 'Stop' and Peek(Name) = Name,

Date - Peek(Date), Null()) as Delta

Resident tmp;

DROP Table tmp;


The results looks promising:

Screenshot_1.jpg

Also, I could find out how you have managed to get Deltas like this:

Screenshot_2.jpg