Logo

dev-resources.site

for different kinds of informations.

How to Create Calendar Table in Power BI?

Published at
12/27/2023
Categories
powerbi
businessintelligence
data
Author
luca1iu
Categories
3 categories in total
powerbi
open
businessintelligence
open
data
open
Author
7 person written this
luca1iu
open
How to Create Calendar Table in Power BI?

Why do you generally need to create a date table in Power BI, while it is not necessary in Tableau?

In Power BI, a date table is necessary because the DAX language does not support built-in date functions, requiring the creation of a date table to perform date-related analysis. In Tableau, no date table is needed as it supports built-in date functions and features for direct use of date fields in analysis.

How to create a date table in Power BI?

To create a date table in Power BI using DAX, you can follow these steps:

  1. Open Power BI Desktop and go to the Modeling tab.
  2. Click on New Table in the Modeling tab to create a new table.

Image description

  1. In the formula bar, enter the DAX code to generate the date table. Here's an example of the DAX code to create a date table:
Calendar = ADDCOLUMNS (
    CALENDAR (date(2021,1,1),date(2023,12,31)),
    "Year", YEAR ( [Date] ),
    "Quarter", ROUNDUP( MONTH ( [Date] )/3,0 ),
    "Month", MONTH ( [Date] ),
    "Week", WEEKNUM([Date]),
    "Year Quarter", YEAR ( [Date] ) & "Q" & ROUNDUP( MONTH ( [Date] )/3,0 ) ,
    "Year Month", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
    "Year Week", YEAR ( [Date] ) * 100 + WEEKNUM ( [Date] ),
    "Weekday", WEEKDAY([Date])
    )
Enter fullscreen mode Exit fullscreen mode

This DAX code creates a calendar table with additional columns for year, quarter, month, week, year quarter, year month, year week, and weekday.

Here's a breakdown of each part of the code:

  1. Calendar = : This is the name of the new table being created.
  2. ADDCOLUMNS ( ... ): This function adds new columns to an existing table.
  3. CALENDAR (date(2021,1,1),date(2023,12,31)): This function creates a table with a single column of dates, starting from January 1, 2021, to December 31, 2023.
  4. Year, YEAR ( [Date] ): This creates a new column named Year which extracts the year from the date in the Date column.
  5. Quarter, ROUNDUP( MONTH ( [Date] )/3,0 ): This creates a new column named Quarter which calculates the quarter based on the month in the Date column. The ROUNDUP function rounds up the result to the nearest whole number.
  6. Month, MONTH ( [Date] ): This creates a new column named Month which extracts the month from the date in the Date column.
  7. Week, WEEKNUM([Date]): This creates a new column named Week which calculates the week number based on the date in the Date column.
  8. Year Quarter, YEAR ( [Date] ) & Q & ROUNDUP( MONTH ( [Date] )/3,0 ): This creates a new column named Year Quarter which combines the year and quarter information.
  9. Year Month, YEAR ( [Date] ) * 100 + MONTH ( [Date] ): This creates a new column named Year Month which combines the year and month information into a single number.
  10. Year Week, YEAR ( [Date] ) * 100 + WEEKNUM ( [Date] ): This creates a new column named Year Week which combines the year and week information into a single number.
  11. Weekday, WEEKDAY([Date]): This creates a new column named Weekday which calculates the day of the week (1 for Sunday, 2 for Monday, and so on) based on the date in the Date column.

In summary, this code creates a calendar table with additional columns to provide various ways of organizing and analyzing date-related data.

dynamic date table

To create a dynamic date table for the most recent three years, you can use the following code.

Calendar = ADDCOLUMNS (
    CALENDAR(DATE(YEAR(TODAY())-1,1,1),DATE(YEAR(TODAY())+1,12,31)),
    "Year", YEAR ( [Date] ),
    "Quarter", ROUNDUP( MONTH ( [Date] )/3,0 ),
    "Month", MONTH ( [Date] ),
    "Week", WEEKNUM([Date]),
    "Year Quarter", YEAR ( [Date] ) & "Q" & ROUNDUP( MONTH ( [Date] )/3,0 ) ,
    "Year Month", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
    "Year Week", YEAR ( [Date] ) * 100 + WEEKNUM ( [Date] ),
    "Weekday", WEEKDAY([Date])
    )
Enter fullscreen mode Exit fullscreen mode

In the current DAX code, the date range is specified as one year ago to one year ahead using DATE(YEAR(TODAY())-1,1,1) and DATE(YEAR(TODAY())+1,12,31). This determines the range of dates included in the dynamic date table.


Explore more

Thank you for taking the time to explore data-related insights with me. I appreciate your engagement.

🚀 Connect with me on LinkedIn

businessintelligence Article's
30 articles in total
Favicon
Why Data Visualization Is Important in 2025
Favicon
AI-Driven Data Analytics: Transforming Business Intelligence
Favicon
Unleashing Data Insights: Harnessing Amazon QuickSight Q's Generative BI for Transformative Analytics
Favicon
Mobile Business Intelligence: Comprehensive Guide & Key Insights
Favicon
All Things Open 2024 Takeaways, Part 2: Transparency
Favicon
2025: Healthcare Business Intelligence Trends to Watch
Favicon
Is Power BI easy to learn?
Favicon
Best Self-service BI Tools for 2025
Favicon
Key Business Intelligence Tools in Project Development
Favicon
5 ChatGPT Business Intelligence Prompts
Favicon
5 ChatGPT Prompts de Inteligencia de Negocios
Favicon
Deploy a lightweight BI solution with your first dashboard in 5 steps
Favicon
Data Visualization Trends in Business Intelligence
Favicon
Cloud BI vs. Traditional BI: Navigating the Future of Business Intelligence
Favicon
Déployer une solution de BI légère avec son premier dashboard en 5 étapes
Favicon
8 Facts To Know About Data Curation in Logistics
Favicon
Building a Data Pipeline for Business Intelligence
Favicon
The Essential Role of a BI Manager
Favicon
Data Lakes vs. Data Warehouses: Choosing the Right Big Data Architecture
Favicon
Unlocking AI Success: The Power of Data Strategy
Favicon
How to Become a Power BI Expert
Favicon
Mastering BI Dashboards for Business Success
Favicon
A Brief Evolution of Data Management: From Business Intelligence to Artificial Intelligence
Favicon
Restrict Access to AWS Quicksight based on source ip
Favicon
Unlocking Sales Potential and Customer Insights with Bold Reports
Favicon
How to Use DAX Studio to Retrieve All Measures in Power BI
Favicon
Quicksight: Un viaje interactivo en el mundo del Business Intelligence junto a AWS
Favicon
Quicksight vs Tableau: No-Nonsence Guide
Favicon
8 Best BI Tools For Small Businesses
Favicon
How to Create Calendar Table in Power BI?

Featured ones: