Power Pivot & DAX course · Lesson 11 of 16
Building a calendar (date) table for Power Pivot
Create a proper date table for the Data Model: Date Table › New, SEQUENCE or Power Query, calculated columns, Sort by Column and Mark as Date Table.
Almost every report slices by time: months, quarters, years, weekdays, fiscal periods. You could add Year and Month calculated columns to the Sales table, but that leads to trouble: months with no sales vanish, time-intelligence functions misbehave, and every fact table needs its own copy. The professional answer is a calendar table (also called a date table or date dimension): one row per day, related to every date column in your facts. This lesson builds one and prepares it for Time intelligence in DAX: TOTALYTD, SAMEPERIODLASTYEAR, DATEADD, DATESINPERIOD.
What makes a proper calendar table
- One row per day, with no gaps, from the first day of the earliest year to the last day of the latest year in your data.
- A Date column of data type Date, unique on every row and with no time portion (midnight).
- Descriptive columns for grouping: Year, Quarter, Month name and number, Weekday, perhaps fiscal year and week.
- A relationship from each fact table's date column to
'Calendar'[Date]. - It is marked as a date table so DAX knows which column holds the dates.
Three ways to create it
Option 1: let Power Pivot build it
In the Power Pivot window choose Design › Date Table › New. Power Pivot looks at the date columns in your model and creates a table called Calendar covering complete years, with ready-made columns such as Year, Month Number, Month and Day Of Week. When your data later extends into a new year, Design › Date Table › Update Range extends it. This is the fastest option, and the table is automatically marked as a date table.
Option 2: a worksheet table with SEQUENCE
In Excel 365 or 2021, put the header Date in A1 of a new sheet and in A2 enter =SEQUENCE(DATE(2026,12,31)-DATE(2025,1,1)+1,1,DATE(2025,1,1)). SEQUENCE spills 730 consecutive dates for 2025 and 2026. Because an Excel table cannot contain a spilled formula, copy the dates and paste them as values (Home › Paste › Values), format them as dates, press Ctrl+T, name the table Calendar and choose Power Pivot › Add to Data Model. You control every detail, but you must extend the list yourself each year.
Option 3: Power Query
Power Query can generate the list of dates from a start and end date (for example the earliest and latest order dates) and refresh it automatically, which is the most robust option for workbooks that are updated for years. The Power Query course on this site covers the technique; load the query with Only Create Connection and Add this data to the Data Model, as shown in Importing data into the Data Model: tables, Power Query and databases.
CALENDAR or CALENDARAUTO to create a calculated table in DAX. Excel's Power Pivot does not support calculated tables, so in Excel the calendar must come from one of the three options above.Adding the descriptive columns
Whichever option you used, add or check these calculated columns in the Calendar table (Data View › Add Column):
Year = YEAR ( 'Calendar'[Date] )
MonthNo = MONTH ( 'Calendar'[Date] )
Month = FORMAT ( 'Calendar'[Date], "mmm" )
Quarter = "Q" & ROUNDUP ( MONTH ( 'Calendar'[Date] ) / 3, 0 )
YearMonth = YEAR ( 'Calendar'[Date] ) * 100 + MONTH ( 'Calendar'[Date] )
Month Year = FORMAT ( 'Calendar'[Date], "mmm yyyy" )
WeekdayNo = WEEKDAY ( 'Calendar'[Date], 2 )
Weekday = FORMAT ( 'Calendar'[Date], "ddd" )
Is Weekend = WEEKDAY ( 'Calendar'[Date], 2 ) > 5| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Date | Year | MonthNo | Month | Quarter | Weekday |
| 2 | 2026-01-01 | 2026 | 1 | Jan | Q1 | Thu |
| 3 | 2026-01-02 | 2026 | 1 | Jan | Q1 | Fri |
| 4 | 2026-01-03 | 2026 | 1 | Jan | Q1 | Sat |
| 5 | 2026-01-04 | 2026 | 1 | Jan | Q1 | Sun |
| 6 | 2026-01-05 | 2026 | 1 | Jan | Q1 | Mon |
| 7 | 2026-01-06 | 2026 | 1 | Jan | Q1 | Tue |
| 8 | 2026-01-07 | 2026 | 1 | Jan | Q1 | Wed |
| 9 | 2026-01-08 | 2026 | 1 | Jan | Q1 | Thu |
The first eight rows of the Calendar table (2026-01-01 is a Thursday).
WEEKDAY ( date, 2 ) numbers Monday as 1 and Sunday as 7, which suits European week conventions. FORMAT returns text, so Month and Weekday are labels; MonthNo, YearMonth and WeekdayNo are their numeric sort keys. Note the single quotes in 'Calendar'[Date]: they are optional for simple table names but harmless, and required when a name contains spaces or clashes with a reserved word.
Sorting months correctly
Put the Month column on rows and Excel sorts the text alphabetically: Feb 2,805, Jan 2,587, Mar 1,248. Fix it once in the model and every PivotTable inherits the correct order:
- In the Power Pivot window, select the Month column in Data View.
- Choose Home › Sort and Filter › Sort by Column › Sort by Column….
- Sort column: Month; By column: MonthNo. Click OK.
- Repeat for Weekday (by WeekdayNo) and Month Year (by YearMonth).
Each label must map to exactly one sort value. Sorting Month by MonthNo works, because every Jan row has MonthNo 1. Sorting Month by YearMonth fails, because Jan would map to both 202501 and 202601, and Power Pivot reports an error. That is why the Month Year label, which is different in every year, is the one sorted by YearMonth.
Relating and marking the table
- In Diagram View, drag
Sales[Date]onto'Calendar'[Date]. The Calendar is the one side, Sales the many side. - Select the Calendar table and choose Design › Mark as Date Table (in some versions Design › Date Table › Mark as Date Table). Pick the Date column and click OK.
- Hide
Sales[Date]from client tools so that report builders use the calendar's columns instead.
What the calendar gives you
With the Calendar related, 'Calendar'[Month] on rows shows every month, and you can write measures that use the calendar itself. For example, average revenue per calendar day:
Revenue := SUM ( Sales[Amount] )
Days := COUNTROWS ( 'Calendar' )
Revenue per Day := DIVIDE ( [Revenue], [Days] )| A | B | C | D | |
|---|---|---|---|---|
| 1 | Month | Revenue | Days | Revenue per Day |
| 2 | Jan | 2587 | 31 | 83.45 |
| 3 | Feb | 2805 | 28 | 100.18 |
| 4 | Mar | 1248 | 31 | 40.26 |
| 5 | Grand Total | 6640 | 90 | 73.78 |
'Calendar'[Month] on rows (sorted by MonthNo), Year slicer = 2026, filtered to Jan–Mar.
January had 2,587 of sales over 31 days, which is 83.45 per day. Counting days from Sales instead of the calendar would only count days with orders, which answers a different question. Weekday analysis works the same way:
| A | B | C | |
|---|---|---|---|
| 1 | Weekday | Revenue | Orders |
| 2 | Mon | 3875 | 4 |
| 3 | Tue | 2135 | 4 |
| 4 | Wed | 630 | 2 |
| 5 | Grand Total | 6640 | 10 |
'Calendar'[Weekday] on rows (sorted by WeekdayNo). Only weekdays with sales appear.
= YEAR ( 'Calendar'[Date] ) + IF ( MONTH ( 'Calendar'[Date] ) >= 7, 1, 0 ) for a year starting in July), an ISO week number and a flag for public holidays loaded from a small table.Check yourself
1. Which is NOT a requirement for a calendar table?
The calendar must contain every day, including days without sales.
2. Why are months listed as Feb, Jan, Mar?
Sort Month by MonthNo in Home › Sort by Column.
3. Can you create a calendar with CALENDARAUTO in Excel Power Pivot?
Use Design › Date Table › New, a worksheet table or Power Query.
4. Which WEEKDAY return type numbers Monday as 1?
WEEKDAY ( date, 2 ) gives Monday = 1 to Sunday = 7.
5. Sales[Date] contains times. What happens with the relationship to Calendar[Date]?
Remove the time part before loading.