Power BI Date Table Template Tutorial

What is the right way of using Date Templates in Power BI reports and dashboards? This article will clarify the question and help to understand the usage of Date tables as templates.

But before we dig deeper, let’s refresh the information we are already familiar with.

CodingSight - Why You Should use Date Templates in Power BI

What is Power BI Date Templates?

A Date table is one of the most commonly used tables in Power BI reports. Without a Date table, the data model working behind the Power BI report lacks the time intelligence features and functions.

A Power BI template is a structure or model that typically contains commonly used tables, relationships, and hierarchies belonging to an organization or an individual. This model is reused in any Power BI report. More information is provided in the previous article:

Centralized Data Modelling using Power BI Templates

A Date template is a precise structure of the Date table that is a background for building reports in the organization. In other words, it is like a built-in Date table that any reports developer or a skilled business user can apply to build Power BI reports.

What is the Difference Between the Date Table and Date Template?

A Date table is typically a table created on the fly through the DAX script in the Model view of a Power BI report. A Date template is a ready Power BI Template that, once created, can be imported into any report. It won’t be necessary to create the Date table in the report, as the template will generate it.

Please refer to the following articles for more data about Date tables in Power BI:

Can we create multiple Date Templates?

It is possible, although it is only recommended if there is a legitimate reason to do so. Refer to the next article to understand how to create multiple date tables using DAX format functions.

Why you Should Use Date Templates?

The benefits are many, including the following:

  • Power BI report developers or internal business users capable of creating Power BI reports do not need to create specific Date tables in each new report they work on;
  • A Date table template can serve as a single source and be easily managed throughout the organization;
  • The possibilities of errors are minimized for creating a Power BI Date table since it is created by the template.

Creating Generic Date Power BI Template: Prerequisites

This article assumes the readers understand the databases and data warehouse business intelligence solutions. Also, it suggests that the readers are familiar with Power BI reporting concepts and have the required tools installed.

If the Microsoft Power BI Desktop is absent in your system, download it from the Microsoft Download Center and install it on your PC/laptop.

Power BI Date Range Filter

At this point, it is crucial to identify the generic business requirements to the date table. First of all, we must ensure which date range is of interest to the organization. Then it will remain consistent for most of the reporting.

Let us assume that our business is interested to see the data across the years from 01 January 2016 till the end of the current year. In this case, we can set up the following range:

  • Start Date: 01 Jan 2016
  • End Date: 31 Dec 2021

However, this strategy will not work next year. Thus, we need to use the dynamic DAX script to get us to the end of the current year, whether it is 2021 or 2022.

This leads us to the Date functions Now() and Year() to configure the end of the current year settings.

How to Create a Date Table in Blank Power BI Report

The first step is creating a Date table in any Power BI report to designate it as a template. There is no direct way to create a Power BI Template without creating a report first.

Open your Power BI Desktop. It will produce the welcome window at once – close it.

Switch to the Data view by clicking the icon on the left (see the screenshot) and then click New table:

Creating a new Date table to become Power BI Template

Now we need to create a Date table that will present the data from 01 January 2016 till the end of the current year. Use the following DAX script:

Date = CALENDAR("01 Jan 2016",DATE(YEAR(NOW()),12,31))
Date Table from 01 Jan 2016 to the end of current year

The Year(Now()) function returns 2021 as Now() and returns the current date. Year() returns the year of the current date. When passed to the Date function with 12 as month and 31 as day, we get the desired date range for the required Date table.

Creating Year Column

Click New Column on the Table Tools tab to create the Year Name column with the following formula:

Year Name = FORMAT('Date'[Date],"\Year yyyy")

The output is as follows:

Creating Year Name column to represent year of the respective date

Creating Quarter Name Column

Click on New Column once again to create the Quarter Name column with the following script:

Quarter Name = FORMAT('Date'[Date],"\Quarter q")

This can be seen below:

Creating Quarter Name column for the Date Table to be turned into Power BI Template

Creating Month Number and Month Name Columns

Similarly, let us create a supporting column called Month Number as follows:

Month Number = FORMAT('Date'[Date],"yyyymm")

Now please change its data type to the Whole number as this helps to sort the Month Name column correctly:

Changing Month Number data type from Text to Whole number for ease of sorting

Create a new column Month Name with the following DAX script:

Month Name = FORMAT('Date'[Date],"MMM yyyy")

When the Month Name column is in focus, we need to sort it by the Month Number column for correct sorting.

Click Sort by column in the Columns tools tab and select Month Number. This is illustrated as follows:

Month Name is sorted by Month Number

Hiding Month Number Column

Since the only purpose to create the Month Number column is to sort it, we can hide it from the report view, as it for internal use entirely.

Right-click on the Month Number column > Hide in report view:

Hiding Month Number column in report view

Create Week Number and Week Name Columns

We need to create the Week Number and Week Name columns and then sort Week Name by Week Number using the DAX script:

Week Number = WEEKNUM('Date'[Date])
Week Name = "Week " & WEEKNUM('Date'[Date])

Just like the way we sorted Month Name by Month Number, please Week Name by Week Number:

Sorting Week Name by Week Number

Also, hide the Week Number column in the report view.

Create Year Quarter Month and Year Month Week Custom Hierarchies

Refer to the previous article Create and Use Custom Date Hierarchies in Power BI to refresh your knowledge.

We have to create the following custom date hierarchies:

  • Year Quarter Month
  • Year Month Week

It is fine to hide the following columns as per standard practice once you have them in the hierarchies:

  • Year Name
  • Quarter Name
  • Month Name
  • Week Name

The report Data Model should look like below:

Hiding the columns that are used in the hierarchy

Mark Table as Date Table

One crucial step is to mark the table as a Date table. Without this, you may not be able to utilize the benefits of using the Date table for time intelligence features.

Go to the Data view and click Mark as date table on the Table Tools tab as shown below:

Mark the table as Date Table

Export as Power BI Template

Finally, open the File menu, click Export,and select Power BI template:

Export as Power BI Template

You can add any description to it. We’ve added Generic Date Template:

You can add any description to it. We’ve added Generic Date Template

Save it as a Generic Date Template to some shared location accessible by other team members:

Save it as a Generic Date Template to some shared location accessible by other team members

Congratulations! You have successfully created a general Date Template to use yourself and share with your team and organization for building reports.

Professional Life Tip

You can also create a Date table from any start date, such as 01 Jan 2016 to exactly the current date by using the following DAX script:

Date = CALENDAR("01 Jan 2016",DATE(YEAR(NOW()),Month(Now()),DAY(NOW())))

Also, you can create a Date table based on the data range determined by the columns, such as OrderDate and ShippingDate of the table imported into the Power BI report:

Date = CALENDAR(FIRSTDATE('Order'[OrderDate]),LASTDATE('Order'[ShippingDate])

Things to Do

Now that you can build a Date template in Power BI, you can try the following exercises to improve your skills:

  1. Try to create another Power BI Template called Multiple Dates Template based on the article How and When to use Multiple Date Tables in Power BI
  2. Try to add the Date table to the existing template mentioned in Centralised Data Modeling using Power BI Templates (mentioned at the beginning of this article)
  3. Try merging the multiple date Power BI template with the template referenced in the article Centralised Data Modelling using Power BI Templates by calling WFH-with-Multiple-Dates-Centralised-PowerBI-Template
Haroon Ashraf

Haroon Ashraf

Haroon's deep interest in logic and reasoning at an early age of his academic career paved his path to become a data professional. He began his professional life as a computer programmer more than 10 years ago working on his first data venture to migrate and rewrite a public sector database driven examination system from IBM AS400 (DB2) to SQL Server 2000 using VB 6.0 and Classic ASP along with developing reports and archiving many years of data. His work and interest revolves around Database-Centric Architectures and his expertise include database and reports design, development, testing, implementation and migration along with Database Life Cycle Management (DLM).

Leave a Reply

Your email address will not be published. Required fields are marked *