Updated March 22, 2023
Introduction to Power BI Calendar
Power BI DAX functions are just amazing and flexible to do many complex calculations. One of the things we can do with Power BI Desktop is by using the CALENDAR function we can create a calendar by mentioning the start and end date. Not only a manual calendar we can create a calendar from the data table as well. Ok, in this article we will take you through CALENDAR function in Power BI.
What does CALENDAR Function do in Power BI?
CALENDAR is a DAX function that can be used to create a calendar table in Power BI based on the starting date and ending date provided. So this is as simple as this, below is the syntax of CALENDAR function.
To create a calendar we need dates so we need to provide Start Date & End Date. For example, if you want to create a calendar for the month of Aug 2019 then the start date will be “01st Aug 2019” and the end date will be “31st Aug 2019”.
One more thing we need to worry about this Calendar function is while providing the start date and end date we cannot simply enter the dates as usual rather we need to make use of DATE function to give Year, Month, and Day separately.
How to Use Calendar Function in Power BI?
Below are the different examples to use Calendar function in Power BI:
Power BI Calendar – Example #1
- For example assume we need to create a Calendar for the month of Aug 2019, in Power BI under the “Modeling” tab click on the “New Table” option.
- This will ask you to name the table, name it as “Aug 2019 Calendar”.
- Now Open Calendar DAX function.
- Since we are creating a Calendar for the month of Aug 2019, we need to provide the Start Date so our start date will be “01st Aug 2019”, so to enter this date we need to use DATE DAX function.
- For this DATE DAX function we need to enter Year, Month, and Day parameters. So enter Year as 2019, Month as 08, and Day as 01.
- The next argument is End Date so to provide end date open one more DATE function.
- For this provide Year as 2019, Month as 08, and Day as 31.
- Ok, close two brackets and hit the Enter key to get the result.
- Here we have date columns starting from 01st Aug 2019 to 31st Aug 2019. One of the problems is it is not formatted properly, it is in the format of “MM-DD-YYYY” with time in front of it. So, change the format of this calendar as shown below.
Now, the calendar format is in the form of “D MMMM, YYYY”.
Power BI Calendar – Example #2
We have seen how to make use of the CALENDAR function to create a calendar table by providing a start date and end date in Power BI. Imagine a scenario where we need to automatically create a calendar table from the actual data table. In such a case we cannot look at what is the least date and what is the highest date, so by using other DAX functions, we can automatically create a calendar.
So you can download the excel workbook from the below link which is used for this example.
For example, we are going to use the below data table.
- This is a huge date table, so upload the same table to Power BI as well.
- From this table, we will create auto-calendar. Create a new table as shown in the previous example and open the CALENDAR DAX function.
- Here we need to use other DAX functions to get the Start Date from the table automatically, use MINX function to get the smallest date from the table.
- For this, first we need from which table we are getting the minimum date, so our table name is “Date_Table” so mention the same as Table name.
- For Expression choose the “Date” column from the mentioned table.
- This will get the minimum date value from the table. Similarly, we need to get the End Date as well, so for this use MAXX function.
- For this function, we need to mention the table name and expression as a date column.
- Ok, that’s all close two-bracket and hit enter to get the new calendar table.
Like this, we can create calendar tables by using the CALENDAR function.
Things to Remember
- By default we get date & time together, so we can change the formatting at any point in time.
- If you are using the CALENDAR DAX function means you have to insert a new table, not as the new column in the existing table.
Recommended Articles
This is a guide to Power BI Calendar. Here we discuss how to use a Calendar DAX Function to create a calendar table based on the starting date and ending date provided in Power BI along with practical examples. You may also look at the following articles to learn more –