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: 
Not applicable

Using a field to populate a new field

Hey all,

I am trying to create a finish date based on the start date of the item after it. I need this to be in the script so that I can use the finish date for multiple items. Here is a sample of the data:

TargetSymbolStageDesignationStageOrdeStageStartDateStageFinishDate
AAAA13/4/2008
AAAC46/20/2011
AAAD054/12/2012
AAAD166/26/2012
AAAD2710/16/2013
AAAE181/15/2012
AAAE292/15/2014
AAAE3103/15/2014
AAAE4119/15/2014
AAAF1122/15/2015
AAAE4114/15/2015
AAAF3145/15/2015
AAAG1156/25/2015
XYZD163/4/2008
XYZE186/13/2008
XYZF1129/1/2008
XYZG1152/25/2009
XYZH175/28/2009
XYZI1810/13/2009
XYZJ191/1/2012
XYZK205/15/2015

The finish date of the Stage is start date of next stage -1day.

the stages can go back and forward again, see row 11, so order needs to be determined by the date that occurs in front of it.

Let me know if I need further clarification

Thanks for all your help.

Vince

12 Replies
MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_181709_Pic1.JPG

table1:

LOAD TargetSymbol,

    StageDesignation,

    StageOrde,

    StageStartDate

FROM [https://community.qlik.com/thread/181709] (html, codepage is 1252, embedded labels, table is @1)

Where Len(TargetSymbol);

Left Join (table1)

LOAD TargetSymbol,

    StageStartDate,

    If(TargetSymbol=Previous(TargetSymbol),Date(Previous(StageStartDate)-1)) as StageFinishDate

Resident table1

Order By TargetSymbol, StageStartDate desc;

hope this helps

regards

Marco

Not applicable
Author

Hey Oleg,

Soooooo close - now I am getting the correct date, but also the startdate of the same stage as well.

Load

*,

   
if(TargetSymbol=Peek(TargetSymbol), date(Previous(StageStartDate)-1, 'M/D/YYYY'), null()) as StageFinishDate

Resident

TargetDBLoad

order by TargetSymbol, StageStartDate desc;



drop table TargetDBLoad;

error3.jpg

Not applicable
Author

When I put the following in, to make sure it was not comparing same stage to same stage - it seems to fix it.

Load

*,

   
if(TargetSymbol=Peek(TargetSymbol) and StageDesignation<>peek(StageDesignation), date(Previous(StageStartDate)-1, 'MM/DD/YYYY')) as StageFinishDate

Resident

TargetDBLoad

order by TargetSymbol, StageStartDate desc;



drop table TargetDBLoad;