Sub topic 3
What a Valid Date Table Must Contain
This chapter assumes you can move around Power BI Desktop's Report, Table, and Model views. It also assumes you know the difference between fact and dimension tables, and that you can write a basic DAX calculated column. Here you learn the rules a table must satisfy before Power BI accepts it as the date table. The next chapters build one.
Why the rules exist
Time intelligence functions such as TOTALYTD and SAMEPERIODLASTYEAR do not look at your sales rows. They move along the date column of a date table. They ask, "which dates belong to this year so far?" and then filter the fact table by those dates. If the date column has gaps or duplicates, or if it stops mid-year, the answer is wrong. Often there is no error, only a wrong number.
When you mark a table as the date table, Power BI checks some of these rules for you. The others are your job.
The requirements
A table can be marked as a date table when it has a column that meets all of the following.
- The column has the Date or Date/Time data type. A text column that looks like a date does not qualify. A whole-number key such as 20260115 does not qualify either.
- Every value is unique. One row per day, so no duplicate dates.
- There are no blanks and no nulls. Every row has a date.
- There are no gaps. The dates run continuously from the first to the last, with no missing days.
- Each date has no time portion, or the same time on every row. If the column holds timestamps such as
2026-01-15 09:30, the same day appears more than once in effect, and the relationship to the fact table breaks.
Two more rules are not enforced when you mark the table, but time intelligence depends on them:
- Whole years. The range should start on January 1 and end on December 31. For a fiscal calendar, it should cover whole fiscal years. A table that ends on 14 March gives wrong year-to-date and prior-year results for that final year.
- Full coverage of the facts. The range must include every date that appears in the fact table. Rows with a date outside the table can't be matched to any date and are grouped under a blank.
How the requirements fit together
Seeing a failure
Suppose you build the date table from only the days that have sales, for example by copying the distinct values of Sales[OrderDate]. Days with no orders, such as weekends or holidays, are missing, so the table has gaps. The following calculated table shows the mistake.
Date Bad =
DISTINCT ( Sales[OrderDate] )This table has unique values and the right type. It still fails the "no gaps" rule, and SAMEPERIODLASTYEAR can return blanks for days whose counterpart a year earlier has no row. The fix is to generate every day in a range, which the next chapter does with CALENDAR.
You can check the rules quickly with measures. Add them to a card or table visual to test a candidate table.
Date Rows = COUNTROWS ( 'Date' )
Distinct Dates = DISTINCTCOUNT ( 'Date'[Date] )
Expected Days =
DATEDIFF ( MIN ( 'Date'[Date] ), MAX ( 'Date'[Date] ), DAY ) + 1If Date Rows, Distinct Dates, and Expected Days are all equal, the table has no duplicates and no gaps. A blank date makes Date Rows larger than Distinct Dates, so it shows up as a mismatch too.
Common errors
| Symptom | Likely cause |
|---|---|
| The "Mark as date table" option is greyed out or rejects the column | The column is not a Date type, or it contains duplicates or blanks |
| Error that the column contains duplicate or missing values | Timestamps, repeated rows, or gaps in the dates |
| Last year's totals are blank only for some days | Gaps in the table |
| Year-to-date for the last year looks too small | The table ends before December 31, or the facts extend past its end |
Exercise
Exercise
A colleague builds a date table from the distinct values of Sales[OrderDate]. It has the Date type and no duplicates or blanks. Which requirement does it most likely violate, and why does that matter for SAMEPERIODLASTYEAR?
Show answer
It most likely has gaps, because days with no sales (weekends, holidays) have no row. SAMEPERIODLASTYEAR shifts the dates in the current filter back one year, so if the matching dates are missing from the table, those days return blank or incomplete results. The table should contain every day in whole years.