Sub topic 9
Marking the Table as the Date Table
This chapter assumes you have built a date table with one row per day, added calendar columns, and related its Date column to a fact table. You should also know basic DAX measures. Here you will tell Power BI which table is your date table, and see what that changes.
What marking does
Marking a table as a date table tells the model that one column holds the calendar for time intelligence. Power BI then validates that column and uses it as the reference for functions such as TOTALYTD and SAMEPERIODLASTYEAR.
It also has a side effect. In Power BI, marking turns off the automatic date/time hierarchy for that column, and it makes the engine ignore filters on other columns of the date table when it evaluates certain time functions. This means your measures behave consistently when a user filters by Month or Year.
Requirements the column must meet
Power BI accepts the column only if it passes these checks:
- The data type is Date or Date/Time.
- Every value is unique.
- There are no blanks and no nulls.
- The dates are continuous, with no missing days between the first and last.
Whole calendar years are good practice, though not a hard rule. The CALENDAR expression from the earlier chapter, which runs from January 1 to December 31, satisfies all of the checks.
Steps to mark the table
- Open Report view or Model view.
- In the Data pane, select the date table.
- Open the Table tools tab and choose Mark as date table.
- Select Mark as date table again in the menu.
- In the dialog, pick the
Datecolumn and select OK.
Power BI runs its validation when you confirm. If a check fails, you get an error that names the problem.
What the dialog checks
| Check | Passes when | Typical cause of failure |
|---|---|---|
| Data type | Column is Date or Date/Time | Column is text, such as a `FORMAT` result |
| Uniqueness | No date appears twice | Table was appended from two overlapping sources |
| No blanks | Every row has a date | A blank row from a failed conversion |
| Continuity | Each day exists once | Rows filtered out in Power Query |
Verifying the effect
After marking, a time intelligence measure should work from the date table alone. Add a matrix with 'Date'[Year-Month] on rows and these measures:
Total Sales = SUM ( Sales[Amount] )
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )
Sales PY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )Check three things. Sales YTD should restart each January. Sales PY should be blank for the first year, because no earlier data exists. The monthly values of Sales PY should equal Total Sales from the same month a year before.
Common mistakes
- Marking a table that is not related to the fact table. The mark succeeds, but measures return the same value for every period because nothing filters the facts.
- Using a fact table's date column. Order dates repeat and have gaps, so validation fails. Use the dedicated date table.
- Skipping the mark and relying on
TOTALYTDanyway. Simple cases often still work, but results can differ when filters touch other date table columns. - Hiding the wrong thing. Hide the fact table's date column in Report view so report authors use the date table's columns instead.
Exercises
Exercise
You try to mark a table as the date table and Power BI reports an error. The table was built from Sales[OrderDate] values with VALUES ( Sales[OrderDate] ). Why does it fail, and how do you fix it?
Show answer
The values include only days on which orders occurred, so the dates have gaps and fail the continuity check. Build the table with CALENDAR (or CALENDARAUTO) so every day between the start and end date is present, then mark it.
Exercise
After marking the table, Sales PY shows the same number as Total Sales in every row. What is the most likely cause?
Show answer
The date table is not related to the fact table, or the relationship is inactive, so the date filter never reaches Sales. Create or activate the relationship from 'Date'[Date] to the fact table date column.