Power BI: create an automatically updated calendar

The year of this calendar will be updated automatically, it is quite useful so there is no need to change it manually every year. The calendar can be the last 12 months, or between another and current year. To do that, I will create a calculated table (DAX table) by going to the “data view” then select “new table”:

power bi

Put this formula:


var FullCalendar = ADDCOLUMNS(CALENDAR(YEAR(NOW())-1&"/1/1",YEAR(NOW())&"/12/31"),"calendar",[Date])
return
SUMMARIZE(FullCalendar,[calendar])             
              

It will create a daily calendar:

  • from the full last year: YEAR(NOW())-1
  • to the full current year: YEAR(NOW())

NOTE: for more past years, change “-1” by another number

In the picture, I changed the table name from “table” to “calendar”:

power bi

I can add new columns by clicking on “new column” to display the month, quarter and/or the year by putting this formula:

  • For the month: FORMAT([argument],"MMMM")
    power bi
    NOTE:
    • For the short month name, put MMM (3 Ms instead of 4 Ms)
    • To get the name of the current month: FORMAT(NOW(),"MMMM")
    • To get the name of the previous or next month (change -1 by +1): FORMAT(DATE(1,MONTH(NOW())-1,1),"MMMM")
  • For the quarter: FORMAT([argument],"Q")
    power bi
    NOTE: to show Q1, Q2, Q3 and Q4, change Q by \QQ
  • For the year: FORMAT([argument],"YYYY")
    power bi
    NOTE: for the short year, put YY

NOTE:

  • Change “argument” by the name of your column
  • You can combine, for instance FORMAT([argument],"YYYY-MM")

The other option is to put what I need in my calendar formula:

power bi

To create a monthly calendar:


var FullCalendar = ADDCOLUMNS(CALENDAR(YEAR(NOW())-1&"/1/1",YEAR(NOW())&"/12/31"),"calendar",FORMAT([Date],"YYYY MM"))
return
SUMMARIZE(FullCalendar,[calendar])             
              
power bi

Once done, select the column and in “data type”, change “text” to “date”:

power bi power bi

If I want to show only the last 12 months, I will use this formula:


var FullCalendar = ADDCOLUMNS(CALENDAR(YEAR(NOW())-1&"/"&MONTH(NOW())&"/"&DAY(NOW()),YEAR(NOW())&"/"&MONTH(NOW())&"/"&DAY(NOW())),"calendar",[Date],"month",FORMAT([Date],"YYYY-MM"))
return
SUMMARIZE(FullCalendar,[calendar],[month])
power bi

When I will create a chart, I just have to configure the filter like that:

power bi

Don’t forget to click on “apply filter” to apply the change.

Interesting Topics