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

Fill in Missing Rows from Date

Hello,

I have the following table with columns:

- DATE: Format DD/MM/YYYY

DATEYEAR_WEEKWEEKCAMPAIGNVALUEDAY
7/3/20202020-101019-205sat
14/3/20202020-111119-208sat
21/3/20202020-121219-203sat
28/3/20202020-131319-207sat
4/4/20202020-141419-204sat
11/4/20202020-151519-206sat
18/4/20202020-161619-208sat
25/4/20202020-171719-2025sat
2/5/20202020-181819-2010sat
3/5/20202020-191919-2010sun
4/5/20202020-191919-2010mon

 

So I need to generate a new row each day with the same data, except fields DATE and YEAR_WEEK (this field has the number of the week). And this would be my data on saturday 09/05/2020 (DD/MM/YYYY):

DATEYEAR_WEEKWEEKCAMPAIGNVALUEDAY
7/3/20202020-101019-205sat
14/3/20202020-111119-208sat
21/3/20202020-121219-203sat
28/3/20202020-131319-207sat
4/4/20202020-141419-204sat
11/4/20202020-151519-206sat
18/4/20202020-161619-208sat
25/4/20202020-171719-2025sat
2/5/20202020-181819-2010sat
3/5/20202020-191919-2010sun
4/5/20202020-191919-2010mon
5/5/20202020-191919-2010tue
6/5/20202020-191919-2010wed
7/5/20202020-191919-2010thu
8/5/20202020-191919-2010fri
9/5/20202020-191919-2010sat

 

But on sunday, 10/05 (DD/MM), I would need to delete those records in blue because when the week is over, I need to keep only the record from saturday:

DATEYEAR_WEEKWEEKCAMPAIGNVALUEDAY
7/3/20202020-101019-205sat
14/3/20202020-111119-208sat
21/3/20202020-121219-203sat
28/3/20202020-131319-207sat
4/4/20202020-141419-204sat
11/4/20202020-151519-206sat
18/4/20202020-161619-208sat
25/4/20202020-171719-2025sat
2/5/20202020-181819-2010sat
9/5/20202020-191919-2010sat
10/5/20202020-192019-2010sun

 

And then repeat the process automatically.

Is there any way to do that by script?

Thank you!

1 Solution

Accepted Solutions
Taoufiq_Zarra

@AleRods88  A very nice practice, thank you 😁

attached you'll find the qlikview fil.

Script :

 

InitialData:
/*
LOAD Date(Date#(DATE,'DD/MM/YYYY')) as DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, Date(Date#(DATE,'DD/MM/YYYY'),'WWW') as DAY INLINE [
    DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
    7/3/2020, 2020-10, 10, 19-20, 5, sat
    14/3/2020, 2020-11, 11, 19-20, 8, sat
    21/3/2020, 2020-12, 12, 19-20, 3, sat
    28/3/2020, 2020-13, 13, 19-20, 7, sat
    4/4/2020, 2020-14, 14, 19-20, 4, sat
    11/4/2020, 2020-15, 15, 19-20, 6, sat
    18/4/2020, 2020-16, 16, 19-20, 8, sat
    25/4/2020, 2020-17, 17, 19-20, 25, sat
    2/5/2020, 2020-18, 18, 19-20, 10, sat
    3/5/2020, 2020-19, 19, 19-20, 10, sun
    4/5/2020, 2020-19, 19, 19-20, 10, mon
];
*/

LOAD Date(Date#(DATE,'DD/MM/YYYY')) as DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, Date(Date#(DATE,'DD/MM/YYYY'),'WWW') as DAY INLINE [
    DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
    7/3/2020, 2020-10, 10, 19-20, 5, sat
    14/3/2020, 2020-11, 11, 19-20, 8, sat
    21/3/2020, 2020-12, 12, 19-20, 3, sat
    28/3/2020, 2020-13, 13, 19-20, 7, sat
    4/4/2020, 2020-14, 14, 19-20, 4, sat
    11/4/2020, 2020-15, 15, 19-20, 6, sat
    18/4/2020, 2020-16, 16, 19-20, 8, sat
    25/4/2020, 2020-17, 17, 19-20, 25, sat
    2/5/2020, 2020-18, 18, 19-20, 10, sat
    9/5/2020, 2020-19, 19, 19-20, 10, sat
    10/5/2020, 2020-19, 20, 19-20, 10, sun
];


Temp1:
noconcatenate

load * resident InitialData where num(WeekDay(Date(Date#(DATE,'DD/MM/YYYY'))))=5;

Temp2:
noconcatenate

load Max(DATE) as MaxDate resident InitialData ;

Let VMaxdate=num(WeekDay(peek('MaxDate',0,'Temp2')));

drop table Temp2;

let concatenate=0;

if $(VMaxdate) <> 5 then

	let concatenate=1;
	
			Temp3:
			noconcatenate
			First 1 load * resident InitialData order by DATE DESC;
			let Vmin=num(floor(weekStart(peek('DATE',0,'Temp3'),0,6)));
			let Vmax=num(floor(WeekEnd(peek('DATE',0,'Temp3'),0,6)));
			let vCAMPAIGN=peek('CAMPAIGN',0,'Temp3');
			let vVALUE=peek('VALUE',0,'Temp3');
			
			drop table Temp3;
			
				Table:
				noconcatenate
							
							Load
			
			               Date($(Vmin) + IterNo() - 1,'DD/MM/YYYY') as DATE,
			               week($(Vmin) + IterNo() - 1) As WEEK,
			               Year($(Vmin) + IterNo() - 1)&'-'&week($(Vmin) + IterNo() - 1) as YEAR_WEEK,
			               Date(($(Vmin) + IterNo() - 1),'WWW') as DAY,
						   '$(vCAMPAIGN)' as CAMPAIGN,
						   '$(vVALUE)' as VALUE 
			               AutoGenerate 1 While $(Vmin) + IterNo() -1 <= $(Vmax);
	
	       
end if

drop table InitialData;



if $(concatenate) = 1 then 
			output:
			noconcatenate
			load * resident Temp1;
			concatenate load * resident Table;
			drop table Temp1,Table;
else
			output:
			noconcatenate
			load * resident Temp1;
			drop table Temp1;
end if

the result obtained for the sample 1 :

DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
7/3/2020, 2020-10, 10, 19-20, 5, sat
14/3/2020, 2020-11, 11, 19-20, 8, sat
21/3/2020, 2020-12, 12, 19-20, 3, sat
28/3/2020, 2020-13, 13, 19-20, 7, sat
4/4/2020, 2020-14, 14, 19-20, 4, sat
11/4/2020, 2020-15, 15, 19-20, 6, sat
18/4/2020, 2020-16, 16, 19-20, 8, sat
25/4/2020, 2020-17, 17, 19-20, 25, sat
2/5/2020, 2020-18, 18, 19-20, 10, sat
3/5/2020, 2020-19, 19, 19-20, 10, sun
4/5/2020, 2020-19, 19, 19-20, 10, mon

Capture1.JPG

 

and for this sample :

7/3/2020, 2020-10, 10, 19-20, 5, sat
14/3/2020, 2020-11, 11, 19-20, 8, sat
21/3/2020, 2020-12, 12, 19-20, 3, sat
28/3/2020, 2020-13, 13, 19-20, 7, sat
4/4/2020, 2020-14, 14, 19-20, 4, sat
11/4/2020, 2020-15, 15, 19-20, 6, sat
18/4/2020, 2020-16, 16, 19-20, 8, sat
25/4/2020, 2020-17, 17, 19-20, 25, sat
2/5/2020, 2020-18, 18, 19-20, 10, sat
9/5/2020, 2020-19, 19, 19-20, 10, sat
10/5/2020, 2020-19, 20, 19-20, 10, sun

Capture2.JPG

 

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

1 Reply
Taoufiq_Zarra

@AleRods88  A very nice practice, thank you 😁

attached you'll find the qlikview fil.

Script :

 

InitialData:
/*
LOAD Date(Date#(DATE,'DD/MM/YYYY')) as DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, Date(Date#(DATE,'DD/MM/YYYY'),'WWW') as DAY INLINE [
    DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
    7/3/2020, 2020-10, 10, 19-20, 5, sat
    14/3/2020, 2020-11, 11, 19-20, 8, sat
    21/3/2020, 2020-12, 12, 19-20, 3, sat
    28/3/2020, 2020-13, 13, 19-20, 7, sat
    4/4/2020, 2020-14, 14, 19-20, 4, sat
    11/4/2020, 2020-15, 15, 19-20, 6, sat
    18/4/2020, 2020-16, 16, 19-20, 8, sat
    25/4/2020, 2020-17, 17, 19-20, 25, sat
    2/5/2020, 2020-18, 18, 19-20, 10, sat
    3/5/2020, 2020-19, 19, 19-20, 10, sun
    4/5/2020, 2020-19, 19, 19-20, 10, mon
];
*/

LOAD Date(Date#(DATE,'DD/MM/YYYY')) as DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, Date(Date#(DATE,'DD/MM/YYYY'),'WWW') as DAY INLINE [
    DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
    7/3/2020, 2020-10, 10, 19-20, 5, sat
    14/3/2020, 2020-11, 11, 19-20, 8, sat
    21/3/2020, 2020-12, 12, 19-20, 3, sat
    28/3/2020, 2020-13, 13, 19-20, 7, sat
    4/4/2020, 2020-14, 14, 19-20, 4, sat
    11/4/2020, 2020-15, 15, 19-20, 6, sat
    18/4/2020, 2020-16, 16, 19-20, 8, sat
    25/4/2020, 2020-17, 17, 19-20, 25, sat
    2/5/2020, 2020-18, 18, 19-20, 10, sat
    9/5/2020, 2020-19, 19, 19-20, 10, sat
    10/5/2020, 2020-19, 20, 19-20, 10, sun
];


Temp1:
noconcatenate

load * resident InitialData where num(WeekDay(Date(Date#(DATE,'DD/MM/YYYY'))))=5;

Temp2:
noconcatenate

load Max(DATE) as MaxDate resident InitialData ;

Let VMaxdate=num(WeekDay(peek('MaxDate',0,'Temp2')));

drop table Temp2;

let concatenate=0;

if $(VMaxdate) <> 5 then

	let concatenate=1;
	
			Temp3:
			noconcatenate
			First 1 load * resident InitialData order by DATE DESC;
			let Vmin=num(floor(weekStart(peek('DATE',0,'Temp3'),0,6)));
			let Vmax=num(floor(WeekEnd(peek('DATE',0,'Temp3'),0,6)));
			let vCAMPAIGN=peek('CAMPAIGN',0,'Temp3');
			let vVALUE=peek('VALUE',0,'Temp3');
			
			drop table Temp3;
			
				Table:
				noconcatenate
							
							Load
			
			               Date($(Vmin) + IterNo() - 1,'DD/MM/YYYY') as DATE,
			               week($(Vmin) + IterNo() - 1) As WEEK,
			               Year($(Vmin) + IterNo() - 1)&'-'&week($(Vmin) + IterNo() - 1) as YEAR_WEEK,
			               Date(($(Vmin) + IterNo() - 1),'WWW') as DAY,
						   '$(vCAMPAIGN)' as CAMPAIGN,
						   '$(vVALUE)' as VALUE 
			               AutoGenerate 1 While $(Vmin) + IterNo() -1 <= $(Vmax);
	
	       
end if

drop table InitialData;



if $(concatenate) = 1 then 
			output:
			noconcatenate
			load * resident Temp1;
			concatenate load * resident Table;
			drop table Temp1,Table;
else
			output:
			noconcatenate
			load * resident Temp1;
			drop table Temp1;
end if

the result obtained for the sample 1 :

DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
7/3/2020, 2020-10, 10, 19-20, 5, sat
14/3/2020, 2020-11, 11, 19-20, 8, sat
21/3/2020, 2020-12, 12, 19-20, 3, sat
28/3/2020, 2020-13, 13, 19-20, 7, sat
4/4/2020, 2020-14, 14, 19-20, 4, sat
11/4/2020, 2020-15, 15, 19-20, 6, sat
18/4/2020, 2020-16, 16, 19-20, 8, sat
25/4/2020, 2020-17, 17, 19-20, 25, sat
2/5/2020, 2020-18, 18, 19-20, 10, sat
3/5/2020, 2020-19, 19, 19-20, 10, sun
4/5/2020, 2020-19, 19, 19-20, 10, mon

Capture1.JPG

 

and for this sample :

7/3/2020, 2020-10, 10, 19-20, 5, sat
14/3/2020, 2020-11, 11, 19-20, 8, sat
21/3/2020, 2020-12, 12, 19-20, 3, sat
28/3/2020, 2020-13, 13, 19-20, 7, sat
4/4/2020, 2020-14, 14, 19-20, 4, sat
11/4/2020, 2020-15, 15, 19-20, 6, sat
18/4/2020, 2020-16, 16, 19-20, 8, sat
25/4/2020, 2020-17, 17, 19-20, 25, sat
2/5/2020, 2020-18, 18, 19-20, 10, sat
9/5/2020, 2020-19, 19, 19-20, 10, sat
10/5/2020, 2020-19, 20, 19-20, 10, sun

Capture2.JPG

 

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉