Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

I need to derive end date from rowno( 2) -1 of start date. Need help in Scripting.

Below is my data.

 

Date1
12/26/2008
12/26/2009
12/26/2010
12/26/2011
12/25/2012
12/25/2013
12/25/2014
12/25/2015
12/24/2016
12/24/2017

Output should be like .

 

Date1Enddate
12/26/200812/25/2009
12/26/200912/25/2010
12/26/201012/25/2011
12/26/201112/24/2012
12/25/201212/24/2013
12/25/201312/24/2014
12/25/201412/24/2015
12/25/201512/23/2016
12/24/201612/23/2017
12/24/2017Today()

Plz help.

6 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

If I understand you correctly, you want EndDate to be the start date of the following row?

To do this, resident load the data sorted by date descending:

     LOAD Date1 as StartDate,

          Alt(Previous(Date1), 0) as EndDate,

          ...

     Resident Table1

     Order By Date1 DESC;

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

Thank you , it is giving me the output which is similar to my requirement. but

1. i would not require it in desc format. I need it as it is.

2. I would like to get the data using peek function...

Plz help

ahaahaaha
Partner - Master
Partner - Master

Hi,

Maybe something like this

Table1:

LOAD

Date#(Date1, 'MM/DD/YYYY') as Date1

Inline [

Date1

12/26/2008

12/26/2009

12/26/2010

12/26/2011

12/25/2012

12/25/2013

12/25/2014

12/25/2015

12/24/2016

12/24/2017];

Table2:

LOAD

Date(Date#(Date1, 'MM/DD/YYYY'), 'MM/DD/YYYY') as StartDay,

Date(Date(Date#(Previous(Date1), 'MM/DD/YYYY')) - 1, 'MM/DD/YYYY') as EndDay

Resident Table1

Order By Date1 desc;

NoConcatenate

Table3:

LOAD

StartDay ,

If(Isnull(EndDay) = 0, EndDay, Today()) as EndDay

Resident Table2;

DROP Tables Table1, Table2;

Result

1.jpg

Regards,

Andrey

Anonymous
Not applicable
Author

Thank you Andrey..

Will the same be done with the help of peek function.using a for loop like.

Let vdate= i;

for i = 1 to max(rowno())

If(peeK('date1',1) -Peek('date1',2) = 365, Peek('date1',2) -1, Today()) as Enddate

Next

I need script for the above example..where i increments till max row.

jonathandienst
Partner - Champion III
Partner - Champion III

>>1. i would not require it in desc format. I need it as it is.

Qlik has no lookahead function, so you need to sort it in desc order to do the equivalent.This has no affect on the front end sorting.

2. I would like to get the data using peek function...

There is really no need. Peek is used to read previous output rows, Previous reads previous input rows. In your case, it makes little difference, although Peek may be very slightly slower.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

I would not do it in a loop like that. Avoid row by row operations except for extremely small data sets. But the script will not work - you can't embed a for loop in a LOAD statement.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein