top of page

How to create a Date Table in Power BI using DAX

  • Nov 22, 2023
  • 3 min read

Updated: Jan 24

A date table is an important component of any Power BI model that makes use of time-series data. The date table provides a standardised way for representing dates and related attributes such as year, month and so on in your model.


Below are some of the benefits of using a date table:

  • Efficient Date Filtering and Grouping: A date table makes it efficient to filter and group data by date. This makes it easier to to analyse trends and patterns over time.

  • Consistent Date Formatting: Ensures consistent formatting of dates across all visuals and reports.

  • Relationship Management: A date table simplifies the creation and management of relationships between tables in the model.

  • Time Intelligence Calculations: Date tables enable calculations of time intelligence measures, such as year-to-date comparisons.

In this article I am going to show you the steps to follow to create a Date table using DAX:


STEP 1


In Power BI desktop click on Table view on the left hand side of the report canvas and then select New Table.


New Table


STEP 2


In the expression builder, input the following DAX formula to generate a list of dates:


DateTable = CALENDAR(DATE (2023, 1, 1), DATE (2023, 12, 31))


The CALENDAR function is used to generate a list of dates by specifying a Start Date and an End Date. For more info on the CALENDAR function check out the official Microsoft documentation here.


Dates

The CALENDERAUTO function can also be used if there is an existing set of dates in your model.



STEP 3


Once you have generated a list of dates you will see they are in the format

yyyy-mm-dd hh:mm:ss AM


You can change the date format by clicking on the Date column and then selecting your required format from the Format dropdown option.

Format

I usually use the format yyyy-mm-dd as there will be a default time component associated with your dates which is not useful in this instance.



Step 4


Once you have configured your Date column, you can use it to generate other columns such as Year, Month etc.


In the example below we will generate a Year column from the existing Date.


To do this, right click on the Date column and select New Column. In the expression builder input the following formula to create the Year column:


Year = YEAR(DateTable[Date])


Year

As you can see from the above image, a new column has been generated that contains the year associated with each date.



Step 5


Once your date table is set up you will need to mark it as the date table in your model.


The reason we mark a table as a date table in Power BI is to enable time intelligence calculations and to ensure accurate date-based analysis.


When a table is marked as a date table, it informs Power BI that the table contains dates and allows it to apply appropriate date-related functions and behaviors.


To mark your table as a date table do the following:


Right click on your table in the Data Plane and select Mark as date table.


Date Table

In the dropdown menu, select the Date column and click OK.


Mark as Date Table

You have now successfully marked this as your date table.


Date tables play a vital role in enhancing the performance and usability of Power BI models, particularly those that contain time-series data. By incorporating a well-defined date table into your model, you can effectively filter, group, and analyse data across different time periods, leading to valuable insights and better decision-making.


If you enjoyed this article please like, comment and share this post on your social media platforms.


Happy developing!

Comments


bottom of page