Time Intelligence Functions
Time intelligence functions are functions like TOTALYTD(), TOTALMTD(), TOTALQTD(), DATEADD(), DATESBETWEEN() etc. They enable us to do in thorough time analysis of our data. All business reports will surely need TOTALYTD() function, meaning a sum of values from the beginning of the year up to the current date. Time intelligence functions only work on continuous dates, meaning a Calendar table. We will take a closer look at time intelligence functions in upcoming parts of the Time Intelligence in Data Modelling Series.
How to Create Calendar Table
There are multiple ways to create a Calendar table. A fast way is to use the CALENDAR(StartDate, EndDate) function that creates a table of all the dates between the StartDate and EndDate. StartDate and EndDate should be the first and last day of the year, to ensure time intelligence functions work properly. We can then add attributes like day, week, month and quarter manually. The problem here is you that you hardcoded the start and end date. If later (or earlier) dates appear in the data once you refresh your model, they won’t be included in the calendar.
Another way is to use CALENDARAUTO(), which automagically reads the earliest and latest date in your entire data model and creates a table of all the dates between them. You can read more about this technique here.
This way also has a problem: your data will often have date columns that are irrelevant for business analysis. For example, birth dates of your employees can push the earliest date in your data model 60 years back. You don’t want all those redundant rows in your Calendar table to slow your model down.