QlikView Master Calendar

Embed Size (px)

DESCRIPTION

QlikView Master Calendar Script.

Citation preview

/*************** MinMax Table *************Keeps minimum and maximum Date value from Facts table*/MinMax:LOADMin(Date) as MinDate,Max(Date) as MaxDateRESIDENT Facts;LET vMinDate = Num(Peek('MinDate', 0, 'MinMax')); LET vMaxDate = Num(Peek('MaxDate', 0, 'MinMax')); LET vToday = $(vMaxDate);/*************** Temporary Calendar *************Generates a single table with one field containing all existing dates between MinDate and MaxDate.*/TempCal:LOAD date($(vMinDate) + rowno() - 1) AS TempDate AUTOGENERATE $(vMaxDate) - $(vMinDate) + 1; DROP TABLE MinMax;/*************** Master Calendar ***************Disconnected during the Date Island exercise by renaming TempDate as IslandDate*/MasterCalendar:LOAD//TempDate as IslandDate,TempDate AS Date,Week(TempDate) AS Week,Year(TempDate) AS Year,Month(TempDate) AS Month,Day(TempDate) AS Day,Weekday(TempDate) AS WeekDay,'Q' & ceil(month(TempDate) / 3) AS Quarter,Date(monthstart(TempDate), 'MMM-YYYY') AS MonthYear,Week(TempDate)&'-'&Year(TempDate) AS WeekYear,inyeartodate(TempDate, $(vToday), 0) * -1 AS CurYTDFlag,inyeartodate(TempDate, $(vToday), -1) * -1 AS LastYTDFlag RESIDENT TempCal ORDER BY TempDate ASC;DROP TABLE TempCal;