Stop 10 · Time IntelligenceTopics · 2/9

Creating a Date Table (CALENDAR and Mark as Date Table)

Part of the Power BI Roadmap

In short

Five minutes of DAX gives you a calendar that powers every YTD, last-year and rolling measure you'll write. Build it once, copy it into every new report.

A dedicated date table with one row per day and columns like year, month and quarter can be built with CALENDAR or CALENDARAUTO in DAX, or in Power Query. Marking it as a date table tells Power BI to use it.

The jaadu cranks an old printing press that rolls out a long ribbon of blank calendar pages, then stamps a gold seal on the first page.

Think of it like this

Printing the year planner

At the start of the year, a shop owner in Indore prints a planner: one line per day, with the weekday, month and quarter written beside it. He never wonders what quarter 14 August is, he just looks. CALENDAR prints the days, ADDCOLUMNS writes the labels beside them.

Watch it happen

From nothing to a marked date table

CALENDAR
Add columns
Sort by
Mark
Relate

1/5CALENDAR ( DATE ( 2023, 4, 1 ), DATE ( 2027, 3, 31 ) ) returns one Date column with 1,461 days.

The big ideas

What you need to know

CALENDAR ( start, end )

Gives you exact control over the range. Good for fixed full years.

CALENDARAUTO ( 3 )

Scans every date column in the model and covers full fiscal years ending in March. Watch out for birth dates stretching it back decades.

Sort text columns

Month names sort alphabetically unless you set Sort by column to a number column.

Hide the keys

Hide sort columns and the fact table's date columns so users always slice by the date table.

See it in code

Walk through the code

dax
1Date =2VAR FirstDate = DATE ( 2023, 4, 1 )3VAR LastDate  = DATE ( 2027, 3, 31 )4RETURN5ADDCOLUMNS (6    CALENDAR ( FirstDate, LastDate ),7    "Year", YEAR ( [Date] ),8    "Month No", MONTH ( [Date] ),9    "Month", FORMAT ( [Date], "MMM" ),10    "Month Start", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 ),11    "Month Year", FORMAT ( [Date], "MMM YYYY" ),12    "Year Month No", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),13    "Quarter", "Q" & QUARTER ( [Date] ),14    "Weekday", FORMAT ( [Date], "ddd" ),15    "Weekday No", WEEKDAY ( [Date], 2 )16)

1/5Full fiscal years from April 2023 to March 2027. Adjust these two dates to cover your data.

Modeling > New table. Then sort Month by Month No, Month Year by Year Month No, and mark the table as a date table.

Save yourself the pain

Common mistakes

Oops

Leaving Month to sort by itself, so charts go Apr, Aug, Dec, Feb.

Do this instead

Select the Month column, then Column tools > Sort by column > Month No.

Oops

Forgetting to mark the table as a date table.

Do this instead

Table tools > Mark as date table. Power BI validates it and uses it properly for time functions.

Oops

Letting CALENDARAUTO pick up a Date of Birth column and generate dates from 1960.

Do this instead

Use CALENDAR with explicit dates, or make sure only relevant date columns exist.

Your mission

Your reusable calendar

~25 min

Quick check

What does CALENDARAUTO ( 3 ) do?

Go deeper

  1. 1Create a date table with CALENDAR covering full years of your data.
  2. 2Add Month Name and sort it by Month Number.
  3. 3Turn off Auto date/time in Options once your own date table is in place.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge