kohera-logo-regular.svg

How to create a date table in Power BI in 2 simple steps

A couple of months ago my colleague Franky Leeuwerck wrote an excellent blog post on how to create a complete date table (calendar dimension) in 6 steps in PowerPivot for Excel.

With the introduction of “calculated columns” in Power BI Desktop, things have become even easier. In this blog post I will show you how to create a complete date table is just 2 simple steps.

Step 1 Create the calculated table

Go to the modelling ribbon, where you will now find a new button called “New Table”.

151013b

If you click on this button you can write a DAX expression, similar to how you would have done with the calculated columns and measures before.

The following DAX expression will generate a single column table containing 1 row for every single date between 1 January 2000 and 31 December 2025.

Date =CALENDAR (DATE(2000;1;1); DATE(2025;12;31))

That’s just the start. We will enhance this formula with ADDCOLUMNS()) to add extra calculated columns to the table, such as month, year, day of the week, etc.


Date =
ADDCOLUMNS (
CALENDAR (DATE(2000;1;1); DATE(2025;12;31));
"DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
"Year"; YEAR ( [Date] )
)

151013d

The final formula for the calculated table should look something like this:

Date =
ADDCOLUMNS (
CALENDAR (DATE(2000;1;1); DATE(2025;12;31));
"DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
"Year"; YEAR ( [Date] );
"Monthnumber"; FORMAT ( [Date]; "MM" );
"YearMonthnumber"; FORMAT ( [Date]; "YYYY/MM" );
"YearMonthShort"; FORMAT ( [Date]; "YYYY/mmm" );
"MonthNameShort"; FORMAT ( [Date]; "mmm" );
"MonthNameLong"; FORMAT ( [Date]; "mmmm" );
"DayOfWeekNumber"; WEEKDAY ( [Date] );
"DayOfWeek"; FORMAT ( [Date]; "dddd" );
"DayOfWeekShort"; FORMAT ( [Date]; "ddd" );
"Quarter"; "Q" & FORMAT ( [Date]; "Q" );
"YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" )
)

Step 2 Adjust sort orders

Power BI sorts attribute values alphabetically by default, so for example the names of the months would be sorted like this: April, August, December and so on. But you can easily fix this. Click on the “Sort By Column” button and choose the appropriate column to sort by. For MonthNameShort this would be MonthNumber.

151013e

And that’s it! You can now create a complete date table in Power BI, using the new calculated table feature in Power BI Desktop, in just a few minutes.

Do you want to see a step-by-step video? Just watch our tutorial.

If you want to download the DateTablePowerBISteps.pbix, just fill out your details below.

    Parameter sniffing solved with new Parameter Sensitive Plan Optimization feature

    If you’re someone that works a lot with Microsoft SQL Server, there’s no doubt that you’ve had issues with an issue called “Parameter sniffing” before. Up until now, you had...

    Creating maps with R and Power BI

    The possibilities are infinite when it comes to creating custom visuals in Power BI. As long as you have creativity and knowledge about the right programming language, you can let...

    Sending monitoring alerts through Telegram

    What if you could get the ease of phone notifications for whatever monitoring alerts you need? Then we have a solution for you with the app Telegram. Some of you...

    Send mails with Azure Elastic Database Jobs

    The DatabaseMail feature in SQL Server and Managed Instance is widely used by many professionals. But what if you want a similar functionality in Azure SQL Database? There are options,...

    Sorting matrices in Power BI

    Recently I worked on a Power BI project for a client. They had a SharePoint site where they regularly published articles and wanted to pour view data into a report...

    The world of data is evolving

    The data landscape has changed dramatically over recent years. In the past, we mainly heard that we needed to do as much as possible “cloud-only”—but this trend has become more...