Sub topic 9
Marking the table as the date table
This chapter assumes you can work in Power BI Desktop's Report, Table, and Model views and write basic DAX measures. It also assumes you have already built a Date table (with DAX or Power Query) and related it to a fact table such as Sales. Here you tell Power BI which table and column hold the calendar, and you learn what that changes.
What marking does
A table with one row per day is only an ordinary table to the model until you mark it. Marking declares two things:
- This table is the calendar for the model.
- This column is its unique, continuous date key.
Power BI then checks the column against the date table rules. Once the column passes, time intelligence functions and client tools can rely on those rules.
Marking changes behavior in these places:
- Validation. Power BI refuses to mark a column that has duplicates, blanks, or a non-date data type. You find these problems at the moment of marking, not later as wrong totals.
- DAX time intelligence. Functions such as
TOTALYTD,SAMEPERIODLASTYEAR, andDATEADDget a trusted calendar to work against. Marking also keeps these functions correct when a filter on another column of the date table, such as Month, is active. - Client tools. Analyze in Excel and other tools that read the model use the marked column to offer date filters and date-aware features.
- Automatic date/time. The built-in date hierarchy for the marked table's date column is not needed, so you can stop relying on hidden auto tables. Turn off auto date/time in Options if you want it gone from the whole file.
Marking does not create relationships, fill gaps, or fix data types. It only checks and declares.
Requirements the marked column must meet
The column you choose must satisfy all of these rules.
| Requirement | Why it matters | Typical failure |
|---|---|---|
| Data type is Date (or Date/time) | Time functions operate on true dates, not text or numbers | Dates imported as text such as "2024-03-01" |
| Every value is unique | One row per day is what makes the table a key | Duplicate rows from appending two sources |
| No blanks | A blank is not a valid day | A blank row created by a failed type conversion |
| Dates are continuous | Period shifts count rows, so a missing day shifts the result | A table built from only the dates that have sales |
| Covers whole years | Year-to-date and prior-year logic need January 1 through December 31 | A table that stops in the middle of the last year |
Use the Date data type, not Date/time. If a Date/time column contains times, two rows can fall on the same calendar day and the uniqueness rule fails.
Whole-year coverage is a modeling rule, not a check Power BI enforces. Marking succeeds on a table that runs from March 12 to October 3, but a prior-year comparison for early March would then find no matching days. The CALENDAR example in the earlier chapter avoids this by using January 1 of the first year and December 31 of the last.
How to mark the table
- Open the Report view or the Data view and select the date table in the Data pane.
- On the Table tools ribbon, choose Mark as date table, then Mark as date table again in the menu.
- In the dialog, pick the date column from the drop-down list. Only columns of Date or Date/time type appear.
- Select OK. Power BI validates the column. If validation fails, an error explains which rule was broken.
You can also right-click the table in the Data pane and use the same command. To undo it, open the same menu and clear the marking. The table's data stays unchanged.
Which column to mark
Mark the same column that your relationship uses. In the examples in this tutorial that is 'Date'[Date], which relates to Sales[OrderDate].
Do not mark Year-Month, Month, or any other text column. Those columns are labels for slicers and axes. The marked column must be a true date, one value per day.
The relationship and the marking are separate settings and do not depend on each other. Marking works with no relationship at all, but the table then filters nothing. A relationship works with no marking, but time intelligence is less reliable. You need both.
Common validation errors
Power BI reports a short message when marking fails. These are the usual ones and their fixes:
- The column contains duplicate values. Find them with a distinct-count check, then remove the source of the duplicates. In Power Query, use Remove duplicates on the date column, or fix the join that created them.
- The column contains blank values. Remove rows where the date is null. In a calculated table built with
CALENDAR, blanks are rare. They appear when the table comes from a column that has missing dates, such asCALENDARAUTOover data with nulls. - The column is not a date type. Change the type to Date in Power Query, or change the column data type in the Table tools. For a calculated table, the type is set by the function result, so check the expression.
- Dates are not continuous. Rebuild the table from a start and end date, not from the dates that happen to appear in your facts.
Checking the table after marking
Marking passes on a table that still has coverage problems, so check the data yourself. Open the DAX query view and run this query. It reports the first and last date, the row count, the number of days the range should contain, and the number of blanks.
EVALUATE
ROW (
"First Date", MIN ( 'Date'[Date] ),
"Last Date", MAX ( 'Date'[Date] ),
"Rows", COUNTROWS ( 'Date' ),
"Expected Days", DATEDIFF ( MIN ( 'Date'[Date] ), MAX ( 'Date'[Date] ), DAY ) + 1,
"Blank Dates", COUNTBLANK ( 'Date'[Date] )
)Read the result like this:
RowsandExpected Daysshould be equal. IfRowsis smaller, days are missing. If it is larger, there are duplicates.Blank Datesshould be 0.First Dateshould be January 1 andLast Dateshould be December 31.
Next, confirm that every date in the fact table falls inside the table's range:
EVALUATE
ROW (
"Earliest Order", MIN ( Sales[OrderDate] ),
"Latest Order", MAX ( Sales[OrderDate] ),
"Date Table Start", MIN ( 'Date'[Date] ),
"Date Table End", MAX ( 'Date'[Date] )
)If an order date falls outside the date table, the row has no match. In the report, those sales appear under a blank date, and they drop out of year-to-date and prior-year totals.
Testing with time intelligence measures
A short test confirms that marking and the relationship work together. Create these measures from the earlier chapter, or reuse them if they already exist:
Total Sales = SUM ( Sales[Amount] )
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )
Sales PY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )Put Month, Total Sales, Sales YTD, and Sales PY in a table visual with a Year slicer. Check three things:
Sales YTDfor December equals the sum ofTotal Salesfor the whole year.Sales PYfor each month equalsTotal Salesfor the same month a year earlier.- Months from the first year show a blank
Sales PY, because no earlier data exists. A blank is correct here. A zero or an error would not be.
If a measure returns the same value on every row or ignores the slicer, the relationship is usually the problem, not the marking. Open the Model view and confirm that a solid line connects the Date column to the fact column and that the filter direction points from Date to Sales.
Edge cases and gotchas
- Only one table can be marked. If you have several calendars, such as one for facts and one for budgets, mark the one used by most time intelligence measures. Relate the other to it through a shared key or handle it with its own relationships.
- Marking applies to the model, not to a visual. You mark once, and every report page benefits.
- Changing the column type after marking can break the marking. If a Power Query refresh turns the date into text, the marking is lost or refresh fails. Keep the type step in the query.
- Multiple fact date columns still need relationships. Marking covers the date table itself. For order and ship dates, keep one active relationship and use
USERELATIONSHIPfor the others, as shown in a later chapter. - Fiscal calendars use the same marking. A fiscal year is only extra columns on the same table. You still mark
'Date'[Date].
Summary of the checklist
Before you move on, confirm each item:
- The date column has type Date and the table has one row per day.
- The range runs from January 1 to December 31 and covers all fact dates.
- A relationship connects
'Date'[Date]to each fact date column you use. - The table is marked, using the same
'Date'[Date]column. - The text columns Month and Quarter sort by their numeric columns.
Sales YTDandSales PYgive the results you expect.
Exercise
You mark a Date table successfully. Its first date is 2021-03-15 and its last date is 2024-09-30. A report shows blank Sales PY values for January 2022. What is the likely cause, and how do you fix it?
Show answer
The date table does not cover whole years. It starts on March 15, 2021, so January 2021 has no rows, and the prior-year lookup for January 2022 finds nothing. Marking only checks uniqueness, blanks, and type, so it did not catch this. Rebuild the table to run from January 1, 2021 to December 31, 2024 (for example, with CALENDAR using DATE ( YEAR ( MIN ( Sales[OrderDate] ) ), 1, 1 ) and DATE ( YEAR ( MAX ( Sales[OrderDate] ) ), 12, 31 )), then confirm the range with the check query.
Exercise
Power BI refuses to mark your table and reports duplicate values in the date column. Name two likely causes and one query you can run to confirm the problem.
Show answer
Likely causes are an append of two sources that both contain the same dates, and a Date/time column where several rows fall on the same day with different times. To confirm, compare COUNTROWS ( 'Date' ) with DISTINCTCOUNT ( 'Date'[Date] ) in a DAX query. If they differ, there are duplicates. Remove the duplicates in Power Query and make sure the column type is Date.