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

if fieldname equals then subtract from previous instance


Hi Experts

I hope you can help, I am loading in from a Notepad file and my data looks a bit like the below

NameStageDate TrayStatus
AppleOpen01/01/2012RDY
AppleOpen02/01/2012CMP
AppleBook03/01/2012CMP
AppleReview03/01/2012RDY
AppleReview03/01/2012RUN
AppleReview04/01/2012CMP
AppleBook05/01/2012CMP
AppleReview06/01/2013RDY
AppleReview06/01/2013RUN
AppleReview06/01/2013CMP
AppleClose06/01/2013RUN
AppleClose07/01/2013CMP

Basically its a workflow where the apple is moving to different stages, what I need to do is calculate the stage times , but here's the clincher - the stages are non sequential ie it can move in any order and I only wish for it to calculate when the status is equal to CMP.

So in the load statement something like

if(Status = CMP, date(date(Date Tray)),null()) as [Start Date].

Then

For each [Start Date] - next [Start Date]  as Stage time.

Any advice would really be appreciated

Thanks


A

1 Solution

Accepted Solutions
Not applicable
Author

Hi Anne,

PFA,

Hope this will help

But i dont know how 367 comes??

View solution in original post

5 Replies
Not applicable
Author

NameStageDateStatusTray Time
AppleOpen01/01/2012RDY
AppleOpen02/01/2012CMP1
AppleBook03/01/2012CMP1
AppleReview03/01/2012RDY
AppleReview03/01/2012RUN
AppleReview04/01/2012CMP1
AppleBook05/01/2012CMP367
AppleReview06/01/2013RDY
AppleReview06/01/2013RUN
AppleReview06/01/2013CMP1
AppleClose06/01/2013RUN
AppleClose07/01/2013CMP

So results would look like the above

Not applicable
Author

Hi Anne,

PFA,

Hope this will help

But i dont know how 367 comes??

Not applicable
Author

Hi Adeel

Thanks so much you have helped me understand the logic,

With a slight tweak its perfect for me

Kind regards

A

Not applicable
Author

Could you please share the change..??

It will help us in the future.

Not applicable
Author

Hi Adeel

it was as I didnt specify that there would be other names Name, so I just to sorted by name and I defined CMP date as part of the first table, very small  See full code below (Changes in bold) :

Thanks again

A

Wrkflow:
LOAD Process_Code,
     Application_id as Application_Id,
     Workitem_Id,
     Activity_Code,
     Timestamp(Txn_Date)as Txn_Date,
     State_Code,
     Assigned_User_Id,
     Assigned_Dept_Id,
     Actioned_User_Id,
     applymap('Trays',Activity_Code,null()) as Tray,
     applymap('Trays',Activity_Code,null())& State_Code as Link,
     if(State_Code='CMP',Timestamp(Txn_Date),null()) as [CMP_Date]

    
FROM

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

Wrkflow2:
Load *,1
Resident Wrkflow
Order by Application_Id,CMP_Date,Tray,State_Code;

DROP Table Wrkflow;

Wrkflow3:
Load *,
CMP_Date-if(State_Code='CMP' ,(Previous(CMP_Date)),'') as diff,
if(State_Code='CMP' ,(Previous(CMP_Date)),'') as pre
Resident Wrkflow2;

DROP Table Wrkflow2;