Calendar Dimension or Calendar Table is one of the crucial table in a Power BI model. I never have seen any data warehouse data model which does not have a Calendar table so far in my development. Because, when it comes to data warehousing or dimension modeling you may storing various business processes or events as Facts. So those events anyway occur in particular date or time. So simply there wouldn’t be a Power BI data model without a date table.
In this post, I’m going to share with you how to create a date table within few steps. Actually, there are two DAX measures which we can use to create a date table. Calendar(DAX) and CalendarAuto(Auto).
Calendar(DAX) = You can pass start date and End date as parameters you need to create date table.
CalendarAuto(DAX) = You can use this function without passing any parameter. Then it will generate the dates based on your data model dates.
Calendar(DAX) = You can pass start date and End date as parameters you need to create date table.
CalendarAuto(DAX) = You can use this function without passing any parameter. Then it will generate the dates based on your data model dates.
You can simply copy the below DAX code and paste in your Power BI Desktop DAX editor by selecting New Table in the Modeling tab.
In the code, there are two variables called Date Start and DateEnd which can change the values based on your requirement.
VAR DateStart =
DATE ( 2000, 1, 1 ) -- Calendar Start Date. Change this as per your requirement.
VAR DateEnd =
DATE ( 2050, 12, 31 ) -- Calendar End Date.
VAR CalTab =
ADDCOLUMNS (
CALENDAR ( DateStart, DateEnd ),
"DateKey", FORMAT ( [Date], "YYYYMMDD" ),
"Year", YEAR ( [Date] ),
"MonthNumber", FORMAT ( [Date], "MM" ),
"YearMonthNumber", FORMAT ( [Date], "YYYY-MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY-mmm" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthName", FORMAT ( [Date], "mmmm" ),
"IsWeekDay", IF ( WEEKDAY ( [Date] ) = 7, "No", IF ( WEEKDAY ( [Date] ) = 1, "No", "Yes" ) ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "ddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "-Q"
& FORMAT ( [Date], "Q" )
)
RETURN
CalTab
Create the Calendar Table using above code
Thanks for reading this post. Please share your thoughts on this in the comment section below.


Thanks for sharing the descriptive information on Tableau tutorial. It’s really helpful to me since I'm taking Tableau training. Keep doing the good work and if you are interested to know more on Tableau, do check this Tableau tutorial.:-https://www.youtube.com/watch?v=y8hg5OfCeZQ
ReplyDeleteThanks Deva for the comment. This encourage me to write more and more articles like this. :-)
DeleteGreat post dear. It definitely has increased my knowledge on Tableau. Please keep sharing similar write ups of yours. You can check this too for Tableau tutorial as i have recorded this recently on Tableau. and i'm sure it will be helpful to you.https://www.youtube.com/watch?v=Ny6h82Qy4tA&t=34s
ReplyDeletehttps://www.youtube.com/watch?v=Ny6h82Qy4tA&t=34s
Thanks for the comment. This encourage me to write more and more articles like this. :-)
DeleteWell done! It is so well written and interactive. Keep writing such brilliant piece of work. Glad i came across this post. Last night even i saw similar wonderful Tableau tutorial on youtube so you can check that too for more detailed knowledge on Tableau.https://www.youtube.com/watch?v=Ny6h82Qy4tA&t=34s
ReplyDeleteThanks Kajal for the comment. This encourage me to write more and more articles like this. :-)
ReplyDeleteIt is nice blog Thank you provide important information and I am searching for the same information
ReplyDeleteTableau Online Training