Power BI DAX: CALENDAR, DATE, YEAR, TODAY

Mohamad MahmoodMohamad Mahmood
2 min read
DateTable =
CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2022, 12, 31 ) )

To create a Date Table in Power BI using a DAX expression, you can use the CALENDAR or CALENDARAUTO functions.

The CALENDAR function allows you to specify a date range, while CALENDARAUTO automatically generates a date range based on the data in your model. For example, you can create a Date Table by navigating to the "Modeling" tab, selecting "New Table," and entering a DAX formula like the following:

This will generate a table with a single column of dates, which you can then extend with additional calculated columns to support your date interval filtering and grouping needs.

Scenario

Retail Sales Analysis Over a Decade Objective: The company wants to analyze sales data from the past 10 years to identify trends, seasonal patterns, and growth opportunities.

Sample Data

DateSales Amount
2014-01-01500
2015-01-01600
2016-01-01700
2017-01-01800
2018-01-01900
2019-01-011000
2020-01-011100
2021-01-011200
2022-01-011300
2023-01-011400
2024-01-011500

DAX Code to Create Date Table

DateTable =
VAR var1 =
    YEAR ( TODAY () )
RETURN
    CALENDAR ( DATE ( var1 - 9, 01, 01 ), DATE ( var1, 12, 31 ) )

Explanation

• DateTable: This variable creates a table with dates spanning from January 1, nine years before the current year, to December 31 of the current year.

• var1: Captures the current year using the YEAR(TODAY()) function.

• CALENDAR: Generates a continuous range of dates from the start date (DATE(var1 - 9, 01, 01)) to the end date (DATE(var1, 12, 31)).

Analysis

Using this Date Table, the company can now perform various analyses, such as:

• Year-over-Year Growth: Calculate the percentage growth in sales each year.

• Seasonal Trends: Identify peak sales periods and seasonal patterns.

• Long-term Trends: Analyze overall sales growth or decline over the decade.

• Comparative Analysis: Compare sales performance across different years to identify best and worst-performing years.

This approach helps the company gain valuable insights into its sales performance, enabling data-driven decision-making and strategic planning.

0
Subscribe to my newsletter

Read articles from Mohamad Mahmood directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohamad Mahmood
Mohamad Mahmood

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He studies at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).