Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Talend Cloud AWS EU Scheduled Outage: Starting Tues 26 May 21:00 CEST with expected completion Wed 27 May 01:00 CEST
cancel
Showing results for 
Search instead for 
Did you mean: 
ogatchell
Contributor III
Contributor III

Increase actual Year by 2 Years

I would like to increase the actual years in my Calendar by two years. The actual first and last years in the date field of the Order table, on which the current Calendar is based, are 2010 and 2021 respectively.  The script would change these years to 2012 and 2023 respectively. I have tried AddYears in the Calendar script, but this does not work. 

Thanks in advance for any help!

Here is my Calendar script (note that I have commented attempts below to make this work using the AddYears function):

DateRange:
LOAD
min(Date) as MinDate,
max(Date) as MaxDate
// AddYears(min(Date, 2) as MinDate,---> did not work
// AddYears(max(Date, 2)) as MaxDate,---> did not work
// Min(AddYears(Date, 2)) as MinDate,---> did not work
// Max(AddYears(Date, 2)) as MaxDate,---> did not work
Resident POS;

LET vMinDate = Peek('MinDate',0,'DateRange');
LET vMaxDate = Peek('MaxDate',0,'DateRange');

TempCalDate:
LOAD
date($(vMinDate) + RowNo() -1) as CalDate
AutoGenerate $(vMaxDate) - $(vMinDate) + 1;

Calendar:
LOAD
CalDate as Date,
day(CalDate) as Day,
WeekDay(CalDate) as WeekDay,
Year(CalDate) as Year,
Month(CalDate) as Month,
week(CalDate) as Week,
'Q' & Ceil(month(CalDate)/3) as Quarter,
4*Year(Today())+Ceil(Month(Today())/3)-4*Year(1)-Ceil(Month(1)/3) AS [QuartersAgo],
date(monthstart(CalDate), 'MMM-YYYY') as MonthYear,
date(QuarterStart(CalDate), 'QQ-YYYY') as QuarterYear
Resident TempCalDate
order by CalDate asc;

drop Tables DateRange, TempCalDate;

Labels (1)
4 Replies
anat
Master
Master

LOAD
min(Date) as MinDate,
max(Date) as MaxDate,
 AddYears(min(Date), 2) as MinDate,
 AddYears(max(Date), 2) as MaxDate

resident table

Resident POS;

ogatchell
Contributor III
Contributor III
Author

thanks, Anat 

This script results in the following error. Any other thoughts?

"The following error occurred:

Field names must be unique within table
 
The error occurred here:
DateRange: LOAD min(Date) as MinDate, max(Date) as MaxDate, AddYears(min(Date), 2) as MinDate, AddYears(max(Date), 2) as MaxDate
 
Resident POS
"
anat
Master
Master

field names should be unique in the load script.

DateRange: LOAD min(Date) as MinDate, max(Date) as MaxDate, AddYears(min(Date), 2) as MinDate_add1year, AddYears(max(Date), 2) as MaxDate_add2years
 
Resident POS
ogatchell
Contributor III
Contributor III
Author

thanks, Anat

I think this will work, but I tried another approach and it worked.

I commented the Date field in the POS (i.e., Date table source) and replaced it with "AddYears(Date,2) as Date". 

That did the trick. 

Thanks again for your help!