Master Calendar – Michael Torallo

 QuartersMap: 
 MAPPING LOAD 
 rowno() as Month, 
 'Q' & Ceil (rowno()/3) as Quarter 
 AUTOGENERATE (12); 
 
 Temp: 
 Load 
 min(OrderDate) as minDate, 
 max(OrderDate) as maxDate 
 Resident Orders; 
 
 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); 
 
 MasterCalendar: 
 Load 
 TempDate AS OrderDate, 
 week(TempDate) As Week, 
 Year(TempDate) As Year, 
 Month(TempDate) As Month, 
 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 
 Resident TempCalendar 
 Order By TempDate ASC; 
 Drop Table TempCalendar;

 

Credit: https://community.qlik.com/docs/DOC-8174

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.