DAX for a calendar table

Home Power BI DAX DAX for a calendar table

Most Power BI models require a date table. Just add a new table to your model and copy-paste this code to get one.

Here it is:

dim_Calendar =
// replace these values for the ones in your datamodel
VAR _Startdate = MIN ( Sales[Date] )
VAR _Enddate = MAX ( Sales[Date] )
RETURN
ADDCOLUMNS (
CALENDAR (
    _Startdate,
    _Enddate
),
"Month" , MONTH ( [Date] ),
"MonthName" , FORMAT ( [Date] , "mmmm" ),
"Year" , YEAR ( [Date] ),
"Quarter" , "Q" & QUARTER ( [Date] ),
"YearMonth" , YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
"Day" , DAY ( [Date] )
)