Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Time Intelligence is a neat feature in Power BI, and, if we understand a few necessary aspects of how it works, then designing a robust data model becomes a straightforward task. For a beginner, it becomes elementary that we all understand what it takes to build a robust data model with Time Intelligence. A few frequently used Time-based calculations are Year-over-Year variation, comparing performance from the previous month or previous year the same month, YTD, QTD, and MTD. Time Intelligence functions make this task relatively simple.
Experts strongly recommend the use of a dedicated calendar table in a data model. And if the calendar table is dynamic, then it has added advantages.
We can use the following DAX functions for creating a calendar table: CALENDARAUTO & CALENDAR. These functions return a table of one column of the DateTime data type.
CALENDARAUTO() – It scans all the date columns present in the entire data model, finds the minimum and maximum year referenced, and generates the set of dates between these years.
CALENDAR(Start Date, End Date)- It requires the upper and lower boundaries to generate the set of dates between these dates. The following code generates a simple calendar table called Date, containing all the dates between January 1, 2019, and December 31, 2020.
Date =
CALENDAR(
DATE( 2019,1,1 ),
DATE( 2020,12,31 )
)
You may include more columns in your calendar table:
Calendar Table =
VAR StartYear =
YEAR ( MIN ( factTable[DateColumn] ) ) //Calculate the start year and
VAR EndYear =
YEAR ( MAX ( factTable[DateColumn] ) ) // end year from a date column
RETURN
ADDCOLUMNS (
// Add columns in the calendar table
CALENDAR (
// Creating Calendar [Date] column
DATE ( StartYear, 1, 1 ),
// Start Date
DATE ( EndYear, 12, 31 )
),
"Year", YEAR ( [Date] ),
// Adding column for Year
"Quarter", "Q" & INT ( FORMAT ( [Date], "q" ) ),
// Adding column for quarter
"Month Year", FORMAT ( [Date], "mmm" ) & " "
& YEAR ( [Date] )
)
Once the calendar table is created, one should:
Points to consider while creating the calendar table:
Benefits:
NOTE: Power BI Desktop has a feature called “Auto Date/Time” (can be accessed through Options & Settings > Options> Data Load). When enabled, Power BI automatically creates a calendar table for each Date or DateTime column in the model. These automatic calendar tables have two significant drawbacks:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.