kohera-logo-regular.svg

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

Vector_BG.png

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

Vector_BG.png

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”.

 

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] )
)

 

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.

 

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 below.

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

[contact-form-7 id=”3956″ title=”Download Gated File”]

2319-blog-database-specific-security-featured-image
Database specific security in SQL Server
There are many different ways to secure your database. In this blog post we will give most of them a...
kohera-2312-blog-sql-server-level-security-featured-image
SQL Server security on server level
In this blog, we’re going to look at the options we have for server level security. In SQL Server we...
blog-security_1
Microsoft SQL Server history
Since its inception in 1989, Microsoft SQL Server is a critical component of many organizations' data infrastructure. As data has...
DSC_1388
Aggregaties
Power BI Desktop is een prachtige tool om snel data-analyses te kunnen uitvoeren. Je connecteert op een databron, importeert en...
dba image
DBA is not that scary
Often when talking to people who are looking for a career path in the data world I feel like there...
blog-2303
How do you link an SCD Type 2 table in Power Query?
This article uses a simple example to demonstrate how to link an SCD Type 2 table in Power Query to...