Sub topic 1
Why Time Intelligence Needs a Date Table
Prerequisites
This chapter assumes you can do the following:
- Move between the Report, Table, and Model views in Power BI Desktop.
- Read a data model with tables, columns, and relationships.
- Write basic DAX for calculated columns and measures.
- Tell a fact table (events such as sales) from a dimension table (descriptions such as products or dates).
The problem a date table solves
Time intelligence is the set of DAX functions that compare values across periods, such as year-to-date totals or the same period last year. These functions don't work on a loose column of dates. They need a continuous, complete calendar to shift and group dates against.
Consider a Sales table with an OrderDate column. Sales happen on some days and not others. If a store has no orders on March 3, that date is missing from OrderDate. A function that moves back one year or one month would then work from a list with gaps. The result can be wrong or blank.
A dedicated date table fixes this. It is a dimension table with exactly one row for every day in a range of whole years. It holds the calendar attributes you filter and group by: year, quarter, month, and so on. You relate it to your fact table and use its date column in time intelligence functions.
Automatic date/time and its limits
Power BI Desktop has a setting called automatic date/time. When it is on, Power BI creates a hidden date table for each date column in your model. You can then drag a date field into a visual and drill from year to quarter to month to day without building anything.
This is convenient for a quick report. It falls short in several ways:
| Limit | Effect |
|---|---|
| One hidden table per date column | The model grows, and each table is built separately. |
| Not visible or editable | You can't add fiscal years, week numbers, or holiday flags. |
| Not shared across tables | Two fact tables don't filter by one common calendar. |
| Fixed hierarchy | You can't choose custom sort orders or labels. |
| Limited in DAX | You can't reference the hidden table in your own measures the way you can a real one. |
For anything beyond a single-table report, build your own date table. You can then turn automatic date/time off under File > Options and settings > Options > Data Load. Turning it off also removes the hidden tables and saves memory.
What this means for your model
The approach you will follow across this tutorial has four parts:
- Build one date table with a row for every day of every year in your data.
- Add calendar columns such as year, quarter, and month.
- Relate the table to each fact table on its date column.
- Mark it as the date table, so Power BI knows to use it for time intelligence.
Here is the kind of measure this makes possible. It is shown now for orientation, and you will build it step by step in later chapters.
Total Sales = SUM ( Sales[Amount] )
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )TOTALYTD takes the dates visible in the current filter, finds the start of that year in the 'Date'[Date] column, and totals sales from then to the latest date. With a complete date table, it returns the correct running total for each month, even if a month had no sales on some days.
Common mistakes to avoid
- Using the fact table's date column directly. It has gaps and duplicate dates, so time intelligence can return wrong or blank values.
- Building a calendar that stops at the last sale. A year-to-date or prior-year comparison needs whole years, so the calendar should run from January 1 to December 31.
- Creating several separate date tables for one report. Reuse one table so every visual filters consistently.
Exercise
A Sales table has an OrderDate column with no orders on weekends. Why can't you rely on that column alone for a same-period-last-year measure, and what should you add to the model?
Show answer
OrderDate has gaps (the weekend days are missing) and repeats each date many times, so it is not a continuous calendar of unique days. Time intelligence functions need one row per day with no gaps. Add a dedicated date table that covers every day of whole years, relate it to Sales on the date column, and use its date column in the measure.