Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
L_Hop
Creator
Creator

How to Create Start & End Date using Date Field

Dear Qlikies,

Trying to create 'Start Date' & 'End Date' using 'ODDMTJ' field for each row.

I am having trouble to gettting 'End Date'. End date should be next ODDMTJ value for ODURAB&ODDMTJ group.

I have tried load the original table than left join table with using key 'ODURAB&ODDMTJ' , previous(ODDMTJ) as  'End date' with sort order desc. Last value of the grouped date mostly not expected.

How can I accomplish this task on script side. 

ODURABODDMTJODPAAP
236119/01/2017-393151.2
236119/01/201715726046.8
236106/02/2017-70981824
236106/02/2017-514471.2
236106/02/201720553.6
236106/02/2017493917.6
236111/05/20171785331.2
236111/05/201749537047.6

 

Expected Results.png

Any help would be greatly appreciated.

Thanks in advanced.

1 Solution

Accepted Solutions
dplr-rn
Partner - Master III
Partner - Master III

try soemthing like below script

 

 

MyTable:
load * inline [
ODURAB,	ODDMTJ,	ODPAAP
2361,	19/01/2017,	-393151.2
2361,	19/01/2017,	15726046.8
2361,	06/02/2017,	-70981824
2361,	06/02/2017,	-514471.2
2361,	06/02/2017,	20553.6
2361,	06/02/2017,	493917.6
2361,	11/05/2017,	1785331.2
2361,	11/05/2017,	49537047.6
2362,	07/02/2017,	12324.6
2362,	13/05/2017,	6744.2
];

temp:
load Distinct ODURAB,	ODDMTJ
resident MyTable
order by ODURAB desc,	ODDMTJ desc;
timeframes:
load *
	,ODDMTJ as StrtDate
    , if(Previous(ODURAB)=ODURAB,previous(ODDMTJ)) as EndDate
resident temp    ;
drop table temp;

 

Output

ODURABODDMTJODPAAPStrtDateEndDate
236111/05/20171785331.211/05/201706/02/2017
236111/05/201749537047.611/05/201706/02/2017
236106/02/2017-7098182406/02/201719/01/2017
236106/02/2017-514471.206/02/201719/01/2017
236106/02/201720553.606/02/201719/01/2017
236106/02/2017493917.606/02/201719/01/2017
236119/01/2017-393151.219/01/2017-
236119/01/201715726046.819/01/2017-
236207/02/201712324.607/02/201713/05/2017
236213/05/20176744.213/05/2017-

View solution in original post

3 Replies
dplr-rn
Partner - Master III
Partner - Master III

try soemthing like below script

 

 

MyTable:
load * inline [
ODURAB,	ODDMTJ,	ODPAAP
2361,	19/01/2017,	-393151.2
2361,	19/01/2017,	15726046.8
2361,	06/02/2017,	-70981824
2361,	06/02/2017,	-514471.2
2361,	06/02/2017,	20553.6
2361,	06/02/2017,	493917.6
2361,	11/05/2017,	1785331.2
2361,	11/05/2017,	49537047.6
2362,	07/02/2017,	12324.6
2362,	13/05/2017,	6744.2
];

temp:
load Distinct ODURAB,	ODDMTJ
resident MyTable
order by ODURAB desc,	ODDMTJ desc;
timeframes:
load *
	,ODDMTJ as StrtDate
    , if(Previous(ODURAB)=ODURAB,previous(ODDMTJ)) as EndDate
resident temp    ;
drop table temp;

 

Output

ODURABODDMTJODPAAPStrtDateEndDate
236111/05/20171785331.211/05/201706/02/2017
236111/05/201749537047.611/05/201706/02/2017
236106/02/2017-7098182406/02/201719/01/2017
236106/02/2017-514471.206/02/201719/01/2017
236106/02/201720553.606/02/201719/01/2017
236106/02/2017493917.606/02/201719/01/2017
236119/01/2017-393151.219/01/2017-
236119/01/201715726046.819/01/2017-
236207/02/201712324.607/02/201713/05/2017
236213/05/20176744.213/05/2017-
Vegar
MVP
MVP

Try something  like this. 

 

Intervals:

Load  distinct

ODURAB, ODDMTJ,

ODDMTJ as validTo, 

If(peek('ODDRAB')=ODDRAB, PEEK('ODDMTJ') AS validTo

Resident  Data

Order by 

ODURAB, ODDMTJ desc;

 

Left join Data load * from Intervals;

Drop table Intervals

 

L_Hop
Creator
Creator
Author

Dear Dilipranjith,

Thank you for your kind help.

Script worked as expected.

best regards;