Last active
August 29, 2015 13:57
-
-
Save mikeharding/9692180 to your computer and use it in GitHub Desktop.
QlikView script to generate a master calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QuartersMap: | |
MAPPING LOAD * Inline [ | |
Month, Q | |
1, Q1 | |
2, Q1 | |
3, Q1 | |
4, Q2 | |
5, Q2 | |
6, Q2 | |
7, Q3 | |
8, Q3 | |
9, Q3 | |
10, Q4 | |
11, Q4 | |
12, Q4 | |
]; | |
MonthMap: | |
Mapping LOAD * Inline [ | |
MonthNo, LongMonth | |
1, January | |
2, February | |
3, March | |
4, April | |
5, May | |
6, June | |
7, July | |
8, August | |
9, September | |
10, October | |
11, November | |
12, December | |
]; | |
Temp: | |
Load | |
min(DateKey) as minDate, // Replace DateKey with your Date key field | |
max(DateKey) as maxDate // Replace DateKey with your Date key field | |
Resident SourceTable; // Replace SourceTable with the name of the table containing the DateKey field | |
Let varMinDate = Num(Peek('minDate', 0, 'Temp')); | |
Let varMaxDate = Num(Peek('maxDate', 0, 'Temp')); | |
DROP Table Temp; | |
TempCalendar: | |
LOAD | |
$(varMinDate) + Iterno()-1 As Num, | |
Date($(varMinDate) + IterNo() - 1) as TempDate | |
AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate); | |
Set vFM = 4 ; | |
MasterCalendar: | |
LOAD | |
TempDate AS DateKey, // Replace DateKey with your Date key field | |
week(TempDate) as Week, | |
Year(TempDate) as Year, | |
Year(TempDate) -1 as [PriorYear], | |
Month(TempDate) as Month, | |
Dual(ApplyMap('MonthMap', Month(TempDate), Null()), Month(TempDate)) as MonthLong, | |
Day(TempDate) as Day, | |
YeartoDate(TempDate)*-1 as CurYTDFlag, | |
YeartoDate(TempDate,-1)*-1 as LastYTDFlag, | |
inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12, | |
date(monthstart(TempDate), 'MMM-YYYY') as MonthYear, | |
ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter, | |
Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear, | |
WeekDay(TempDate) as WeekDay | |
// Fiscal Year fields | |
//Year(TempDate) + If(Month(TempDate)>=$(vFM), 1, 0) As [Fiscal Year], | |
//Mod(Month(TempDate)-$(vFM), 12)+1 As [Fiscal Month] | |
Resident TempCalendar | |
Order By TempDate ASC; | |
Drop Table TempCalendar; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adjust the Months to Quarters mapping and the FiscalYear to match your fiscal calendar.