Calendar with flags making set analysis so very simple

    NOTE: A more recent version with added functionality can be found here: Calendar with AsOf Flags, Compare Easter to Easter

     

    Hello

     

    Calendars are one of the first things developed when working with Qlik and most follow a similar format.

     

    Often called “Master Calendar” the name misleads as best practice design means multiple calendars are often
    required. http://community.qlik.com/docs/DOC-6502

     

    Once you have a master calendar you’ll often find yourself creating complex set analysis to calculate date ranges or comparative calculations like Month to Date or Previous Month. You can find some good examples here:

    http://community.qlik.com/docs/DOC-6163

    Set Analysis for Rolling Periods

    Set Analysis for certain Point in Time

     

     

    This QVW describes an alternative way. The calendar here creates all possible combinations of dates and flags their relationship with each other.

    Calendar1.png

    Here we can see it in action. The Date Selected combined with the Flag returns the Possible Key Dates which are linked to the fact table. The Set Analysis becomes very intuitive and easy to maintain:

    Yesterday:=sum({<Date={'$(=max(Date))'},%Flag_PreviousDay_M01={1}>}Sales)

     

     

    Additional flags shown here you take the concept further.

     

    MTD:=sum({<Date={'$(=max(Date))'},%Flag_ThisMonthToDate={1}>} Sales)
    Previous MTD:=sum({<Date={'$(=max(Date))'},%Flag_PreviousMonthComparative_M01={1}>} Sales)
    Previous Month:=sum({<Date={'$(=max(Date))'},%Flag_PreviousMonth_M01={1}>}Sales)
    Same Month Last Year:=sum({<Date={'$(=max(Date))'},%Flag_PreviousMonth_M12={1} >}     Sales)


    This idea was originally shown to me by a colleague Jason Michaelides who was inspired by A New Choice of Armor: The Flag Matrix | iQlik - Everything QlikView. This version takes the concept and by simplifying the code means its easier to understand and allows you to develop further to meet your individual requirements.

     

    The basic development principles:

     

     

    Firstly a standard Calendar is created using AutoGenerate. I also take the opportunity to incorporate Business Day flags (set by loading regional public holidays).

     

    A Cartesian Product is then produced by left Joining Distinct Dates with itself without the key. This gives us all the possible date
    combinations.

     

    I then create the flags; Firstly Point In Time Flags such as Today, This Week, This Month, etc. Then period flags such as Previous Day, Previous Month, Previous Month to Date, etc.

     

    Update - Following the comments I've added more code to the CLEAN UP tab to remove any lines where no flags have been set and any lines where the Possible Date is higher than the selected date which reduces the tables size by over 50%

    Update - Fixed a bug resulting from the previous update

    Update 22-Aug-2014 - Fixed a bug which reduces the number of rows in the final calendar

     

    I hope this of some use to people, I would love to hear your comments and further suggestions.

     

    Richard

    qlikcentral | Understand / Create / Inform