To enable analysis over time a calendar is required. This post describes best practices for creating date tables in your data models.
In Power BI, a date table is a table that meets the following conditions:
- The table includes a column of data type date or date/time, which will be our date column.
- The date column only contains unique values.
- The date column does not contain BLANKs.
- The date column does not have any missing dates.
- The date column does span over full years.
- The table has to be marked as a date table.
You can use several techniques to create a date table for your model:
Use Auto date/time option
The Auto date/time option is both fast and easy to use. To enable or disable the function navigate to File > Options and Settings > Options > Data Load > Time Intelligence
This enables users to work with time intelligence when grouping, filtering, and drilling down through calendar time periods.
Generate with DAX
It is possible to generate a date table by creating a calculated table using DAX functions. There are two functions available for this purpose, CALENDAR or CALENDARAUTO. Both functions return a single column table of dates, but the syntax is slightly different. We will go through the two functions below.
The CALENDAR function is preferred when you want to set a date range. The function requires two values, the start date, and the end date. It is useful to know that these values can be defined by other DAX functions, for example, MIN(Sales[TransDate]) or MAX(Sales[TransDate]). This makes the date range dynamic as it changes with the data in the Sales table. If you instead want to set a static date range utilize the following syntax, CALENDAR(<startDate>, <endDate>).
The CALENDARAUTO function is used when you want the date range to automatically include all dates saved in the model. The advantage of this is that it is not required to extend the table for future years. When the data in the model is refreshed, it triggers a recalculation of the date table. This means the table will automatically be adjusted to new dates in the dataset.
Comments
Post a Comment