Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have the following table with these columns (where DATE format is MM/DD/YYYY):
DATE | YEAR_WEEK | WEEK | CAMPAIGN | VALUE | DAY |
03/07/2020 | 2020-10 | 10 | 19-20 | 5 | sat |
03/14/2020 | 2020-11 | 11 | 19-20 | 8 | sat |
03/21/2020 | 2020-12 | 12 | 19-20 | 3 | sat |
03/28/2020 | 2020-13 | 13 | 19-20 | 7 | sat |
04/04/2020 | 2020-14 | 14 | 19-20 | 4 | sat |
04/11/2020 | 2020-15 | 15 | 19-20 | 6 | sat |
04/18/2020 | 2020-16 | 16 | 19-20 | 8 | sat |
04/25/2020 | 2020-17 | 17 | 19-20 | 25 | sat |
05/02/2020 | 2020-18 | 18 | 19-20 | 10 | sat |
05/09/2020 | 2020-19 | 19 | 19-20 | 10 | sat |
05/16/2020 | 2020-20 | 20 | 19-20 | 10 | sat |
05/23/2020 | 2020-21 | 21 | 19-20 | 10 | sat |
05/30/2020 | 2020-22 | 22 | 19-20 | 10 | sat |
06/06/2020 | 2020-23 | 23 | 19-20 | 10 | sat |
06/13/2020 | 2020-24 | 24 | 19-20 | 10 | sat |
06/20/2020 | 2020-25 | 25 | 19-20 | 10 | sat |
06/23/2020 | 2020-26 | 26 | 19-20 | 10 | tue |
The rows in black are "permanent" (or fixed) and I should always show them. The rows in blue are temporary and vary from day to day (please note that the colors are only for the explanation, but I don't need the colors for the development). So I need to replace the row in blue each day, by using the same data from the previous date, except fields DATE (replacing it for the current date) and YEAR_WEEK (this field has the number of the week).
This means, tomorrow wednesday 06/24/2020 I need to replace the last row in blue (removing tuesday) for this one:
06/24/2020 | 2020-26 | 26 | 19-20 | 10 | wed |
The same for thursday 06/25, friday 06/26 and saturday 06/27. So I would show the data in black rows (permanent) and the blue row (dynamic) for the current day. When I run the script on sunday, I should do 2 things:
1 - Keep the row from saturday like the other rows I have in black in the table (I won't replace this row anymore). So the row for saturday should go from "blue" to "black" (now keeping and always showing this row).
2 - Generate a new row for sunday 06/28, where this row would be replaced by monday 06/29, then tuesday, wednesday, thursday, friday, saturday. And then again, repeat the process automatically: keep the row from saturday and generate a new row on sunday.
Here are a few examples:
DATE | YEAR_WEEK | WEEK | CAMPAIGN | VALUE | DAY |
03/07/2020 | 2020-10 | 10 | 19-20 | 5 | sat |
03/14/2020 | 2020-11 | 11 | 19-20 | 8 | sat |
03/21/2020 | 2020-12 | 12 | 19-20 | 3 | sat |
03/28/2020 | 2020-13 | 13 | 19-20 | 7 | sat |
04/04/2020 | 2020-14 | 14 | 19-20 | 4 | sat |
04/11/2020 | 2020-15 | 15 | 19-20 | 6 | sat |
04/18/2020 | 2020-16 | 16 | 19-20 | 8 | sat |
04/25/2020 | 2020-17 | 17 | 19-20 | 25 | sat |
05/02/2020 | 2020-18 | 18 | 19-20 | 10 | sat |
05/09/2020 | 2020-19 | 19 | 19-20 | 10 | sat |
05/16/2020 | 2020-20 | 20 | 19-20 | 10 | sat |
05/23/2020 | 2020-21 | 21 | 19-20 | 10 | sat |
05/30/2020 | 2020-22 | 22 | 19-20 | 10 | sat |
06/06/2020 | 2020-23 | 23 | 19-20 | 10 | sat |
06/13/2020 | 2020-24 | 24 | 19-20 | 10 | sat |
06/20/2020 | 2020-25 | 25 | 19-20 | 10 | sat |
06/25/2020 | 2020-26 | 26 | 19-20 | 10 | thu |
DATE | YEAR_WEEK | WEEK | CAMPAIGN | VALUE | DAY |
03/07/2020 | 2020-10 | 10 | 19-20 | 5 | sat |
03/14/2020 | 2020-11 | 11 | 19-20 | 8 | sat |
03/21/2020 | 2020-12 | 12 | 19-20 | 3 | sat |
03/28/2020 | 2020-13 | 13 | 19-20 | 7 | sat |
04/04/2020 | 2020-14 | 14 | 19-20 | 4 | sat |
04/11/2020 | 2020-15 | 15 | 19-20 | 6 | sat |
04/18/2020 | 2020-16 | 16 | 19-20 | 8 | sat |
04/25/2020 | 2020-17 | 17 | 19-20 | 25 | sat |
05/02/2020 | 2020-18 | 18 | 19-20 | 10 | sat |
05/09/2020 | 2020-19 | 19 | 19-20 | 10 | sat |
05/16/2020 | 2020-20 | 20 | 19-20 | 10 | sat |
05/23/2020 | 2020-21 | 21 | 19-20 | 10 | sat |
05/30/2020 | 2020-22 | 22 | 19-20 | 10 | sat |
06/06/2020 | 2020-23 | 23 | 19-20 | 10 | sat |
06/13/2020 | 2020-24 | 24 | 19-20 | 10 | sat |
06/20/2020 | 2020-25 | 25 | 19-20 | 10 | sat |
06/27/2020 | 2020-26 | 26 | 19-20 | 10 | sat |
DATE | YEAR_WEEK | WEEK | CAMPAIGN | VALUE | DAY |
03/07/2020 | 2020-10 | 10 | 19-20 | 5 | sat |
03/14/2020 | 2020-11 | 11 | 19-20 | 8 | sat |
03/21/2020 | 2020-12 | 12 | 19-20 | 3 | sat |
03/28/2020 | 2020-13 | 13 | 19-20 | 7 | sat |
04/04/2020 | 2020-14 | 14 | 19-20 | 4 | sat |
04/11/2020 | 2020-15 | 15 | 19-20 | 6 | sat |
04/18/2020 | 2020-16 | 16 | 19-20 | 8 | sat |
04/25/2020 | 2020-17 | 17 | 19-20 | 25 | sat |
05/02/2020 | 2020-18 | 18 | 19-20 | 10 | sat |
05/09/2020 | 2020-19 | 19 | 19-20 | 10 | sat |
05/16/2020 | 2020-20 | 20 | 19-20 | 10 | sat |
05/23/2020 | 2020-21 | 21 | 19-20 | 10 | sat |
05/30/2020 | 2020-22 | 22 | 19-20 | 10 | sat |
06/06/2020 | 2020-23 | 23 | 19-20 | 10 | sat |
06/13/2020 | 2020-24 | 24 | 19-20 | 10 | sat |
06/20/2020 | 2020-25 | 25 | 19-20 | 10 | sat |
06/27/2020 | 2020-26 | 26 | 19-20 | 10 | sat |
06/28/2020 | 2020-27 | 27 | 19-20 | 10 | sun |
DATE | YEAR_WEEK | WEEK | CAMPAIGN | VALUE | DAY |
03/07/2020 | 2020-10 | 10 | 19-20 | 5 | sat |
03/14/2020 | 2020-11 | 11 | 19-20 | 8 | sat |
03/21/2020 | 2020-12 | 12 | 19-20 | 3 | sat |
03/28/2020 | 2020-13 | 13 | 19-20 | 7 | sat |
04/04/2020 | 2020-14 | 14 | 19-20 | 4 | sat |
04/11/2020 | 2020-15 | 15 | 19-20 | 6 | sat |
04/18/2020 | 2020-16 | 16 | 19-20 | 8 | sat |
04/25/2020 | 2020-17 | 17 | 19-20 | 25 | sat |
05/02/2020 | 2020-18 | 18 | 19-20 | 10 | sat |
05/09/2020 | 2020-19 | 19 | 19-20 | 10 | sat |
05/16/2020 | 2020-20 | 20 | 19-20 | 10 | sat |
05/23/2020 | 2020-21 | 21 | 19-20 | 10 | sat |
05/30/2020 | 2020-22 | 22 | 19-20 | 10 | sat |
06/06/2020 | 2020-23 | 23 | 19-20 | 10 | sat |
06/13/2020 | 2020-24 | 24 | 19-20 | 10 | sat |
06/20/2020 | 2020-25 | 25 | 19-20 | 10 | sat |
06/27/2020 | 2020-26 | 26 | 19-20 | 10 | sat |
06/29/2020 | 2020-27 | 27 | 19-20 | 10 | mon |
Is there any way to do that by script? (I would run the script every day).
Thank you!!!
One Solution :
Data:
LOAD * INLINE [
DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
03/07/2020, 2020-10, 10, 19-20, 5, sat
03/14/2020, 2020-11, 11, 19-20, 8, sat
03/21/2020, 2020-12, 12, 19-20, 3, sat
03/28/2020, 2020-13, 13, 19-20, 7, sat
04/04/2020, 2020-14, 14, 19-20, 4, sat
04/11/2020, 2020-15, 15, 19-20, 6, sat
04/18/2020, 2020-16, 16, 19-20, 8, sat
04/25/2020, 2020-17, 17, 19-20, 25, sat
05/02/2020, 2020-18, 18, 19-20, 10, sat
05/09/2020, 2020-19, 19, 19-20, 10, sat
05/16/2020, 2020-20, 20, 19-20, 10, sat
05/23/2020, 2020-21, 21, 19-20, 10, sat
05/30/2020, 2020-22, 22, 19-20, 10, sat
06/06/2020, 2020-23, 23, 19-20, 10, sat
06/13/2020, 2020-24, 24, 19-20, 10, sat
06/20/2020, 2020-25, 25, 19-20, 10, sat
06/23/2020, 2020-26, 26, 19-20, 10, tue
];
Tmp:
noconcatenate
First 1 load DATE as vDATE, YEAR_WEEK as vYEAR_WEEK, WEEK as vWEEK, CAMPAIGN as vCAMPAIGN, VALUE as vVALUE, DAY as vDAY resident Data order by DATE DESC;
let IDtmp=num(WeekDay(Date#(peek('vDATE',0,'Tmp'),'MM/DD/YYYY')));
let Datetmp=peek('vDATE',0,'Tmp');
output:
noconcatenate
load * resident Data where DATE<>'$(Datetmp)';
drop table Data;
if $(IDtmp)<>5 then
load Date(today()) as DATE, Year(today())&'-'&week(today()) as YEAR_WEEK, week(today()) as WEEK,vCAMPAIGN as CAMPAIGN,vVALUE as VALUE, WeekDay(Date(today())) as DAY
resident Tmp;
else
load vDATE as DATE, vYEAR_WEEK as YEAR_WEEK, vWEEK as WEEK, vCAMPAIGN as CAMPAIGN, vVALUE as VALUE, vDAY as DAY resident Tmp;
endif
drop table Tmp;
One Solution :
Data:
LOAD * INLINE [
DATE, YEAR_WEEK, WEEK, CAMPAIGN, VALUE, DAY
03/07/2020, 2020-10, 10, 19-20, 5, sat
03/14/2020, 2020-11, 11, 19-20, 8, sat
03/21/2020, 2020-12, 12, 19-20, 3, sat
03/28/2020, 2020-13, 13, 19-20, 7, sat
04/04/2020, 2020-14, 14, 19-20, 4, sat
04/11/2020, 2020-15, 15, 19-20, 6, sat
04/18/2020, 2020-16, 16, 19-20, 8, sat
04/25/2020, 2020-17, 17, 19-20, 25, sat
05/02/2020, 2020-18, 18, 19-20, 10, sat
05/09/2020, 2020-19, 19, 19-20, 10, sat
05/16/2020, 2020-20, 20, 19-20, 10, sat
05/23/2020, 2020-21, 21, 19-20, 10, sat
05/30/2020, 2020-22, 22, 19-20, 10, sat
06/06/2020, 2020-23, 23, 19-20, 10, sat
06/13/2020, 2020-24, 24, 19-20, 10, sat
06/20/2020, 2020-25, 25, 19-20, 10, sat
06/23/2020, 2020-26, 26, 19-20, 10, tue
];
Tmp:
noconcatenate
First 1 load DATE as vDATE, YEAR_WEEK as vYEAR_WEEK, WEEK as vWEEK, CAMPAIGN as vCAMPAIGN, VALUE as vVALUE, DAY as vDAY resident Data order by DATE DESC;
let IDtmp=num(WeekDay(Date#(peek('vDATE',0,'Tmp'),'MM/DD/YYYY')));
let Datetmp=peek('vDATE',0,'Tmp');
output:
noconcatenate
load * resident Data where DATE<>'$(Datetmp)';
drop table Data;
if $(IDtmp)<>5 then
load Date(today()) as DATE, Year(today())&'-'&week(today()) as YEAR_WEEK, week(today()) as WEEK,vCAMPAIGN as CAMPAIGN,vVALUE as VALUE, WeekDay(Date(today())) as DAY
resident Tmp;
else
load vDATE as DATE, vYEAR_WEEK as YEAR_WEEK, vWEEK as WEEK, vCAMPAIGN as CAMPAIGN, vVALUE as VALUE, vDAY as DAY resident Tmp;
endif
drop table Tmp;
output: