2 Replies Latest reply: Mar 26, 2015 2:50 AM by Ralf Narfeldt RSS

    Please help explain this Master Calender code!

      Hello there!


      I recently came across a Master Calender script in Qlik Sense below. But I do not understand the code for WeekYear and IsLastMonth!


      Can anyone please tell me what each line of code is doing? It looks complicated as I am not familiar with it


      Any breakdwon would be fantastico!!



      // ***** The Master Calendar *****



          TempDate AS OrderDate,

          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, //Splits the months into 3 categories.

          Week(TempDate) & ' - ' &  If(Week(TempDate)=1 and


              If(Match(Week(TempDate),52,53) and


                  Year(TempDate))) as WeekYear,

          If(DayNumberOfYear(TempDate) <= DayNumberOfYear($(vToday)),1,0) as IsInYTD,

          If(DayNumberOfQuarter(TempDate) <= DayNumberOfQuarter($(vToday)),1,0) as IsInQTD,

          If(Day(TempDate) <= Day($(vToday)),1,0) as IsInMTD,

          If(Month(TempDate) <= Month($(vToday)),1,0) as IsCurrentMonth,

          If(Month(AddMonths(TempDate,1)) <= Month($(vToday)),1,0) as IsLastMonth

      RESIDENT CalTemp

      ORDER BY TempDate ASC;


      DROP TABLE CalTemp; // Tidy up the model by removing tables no longer required