DAX - Time Intelligence Flashcards
What do time intelligence functions do?
Enable you to manipulate data using time periods, including days, months, quarters, and years, and then build and compare calculations over those periods.
They are particularly useful for trend analysis, forecasting, and performance comparison.
What are the two types of time intelligence functions?
- Functions that returns a scalar value without requiring CALCULATE
- Functions that returns a table, which has to be used as a filter in a CALCULATE statement
What is required for time intelligence functions to work correctly?
A date dimension table with a column of dates.
What are time-related dimensions?
- Date
- Weeks
- Months
- Quarters
- Years
- Annual Periods
- YTD
- Etc
Benefits of time intelligence
- Identifying trends
- Forecasting and predictive analysis
- Real-time performance monitoring
- Compariative analysis (example year over year)
- Sales and marketing optimization
What are the three classifications of time intelligence?
- Time Comparison Functions
- Aggregate Functions
- Information Functions
What does a Time Comparison Function do?
Compares one date or time to another.
For instance, comparing total revenue with the revenue from the last quarter.
What do aggregate time intelligence functions do?
Show the year-to-date, month-to-date or anything similar.
What do information functions do?
Provide snapshots of information
Like a month-opening or year-end balance. These functions are especially important in financial management.
What does summarizing data over time mean?
Identifying trends, patterns, and anomalies in performance over a specific period.
Examples
Sales per Quarter
Annual Growth
TOTALYTD syntax
TOTALYTD(expression, DateColumn, filter, YearEndDate)
Filter and YearEndDate are optional arguments
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
TOTALYTD example
Sales_YTD=
TOTALYTD(
SUM(Sales[Total Sales]), //Sum total sales
Sales[OrderDate].[Date] //Field to use for the date
)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
How does TOTALYTD work?
It returns the desired expression, for example SUM(Sales), from January 1 to the specified date of the current year.
DATESYTD syntax
DATESYTD(DateColumn, YearEndDate)
YearEndDate is an optional argument. The DateColumn is the column you want to use to calculate YTD
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
How does DATESYTD work?
- It returns a single column table that has dates for the year to date in the current filter context.
What is a good scenario in which to use TOTALYTD?
When you need running totals
What are two other functions that work similarly to DATESYTD?
- DATESMTD
- DATESQTD
Where are DATESYTD, DATESMTD and DATESQTD used?
In the CALCULATE function as a filter context.
DATESYTD Example
Sales_YTD=
CALCULATE(
SUM(Sales[Total Sales]), //Sum of total sales
DATESYTD(Sales[OrderDate].[Date] //Filter context
)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
What does DATESBETWEEN return?
All dates in a specified period
DATESBETWEEN syntax
DATESBETWEEN(DateColumn, StartDate, EndDate)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
DATESBETWEEN example
Summer Sales=
CALCULATE(
SUM(Sales[Total Sales]),
DATESBETWEEN(Sales[OrderDate], //Date Column
DATE(2023, 6, 1), //StartDate
DATE(2023, 8, 31) //EndDate
))
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
What do Time Comparison functions do?
Compare sets of data over specific periods.
Example
Comparing sales from this month to last month
What are three Time Comparison functions?
- SAMEPERIODLSATYEAR
- DATEADD
- PARALLELPERIOD
SAMEPERIODLASTYEAR
- Returns a table that contains a column of dates shifted one year back in time from the dates in the specified DateColumn
- In other words, it compares the current period against the same period last year
SAMEPERIODLASTYEAR syntax
SAMEPERIODLASTYEAR(DateColumn)
SAMEPERIODLASTYEAR Example
Revenue PY=
CALCULATE(
[Revenue],
SAMEPERIODLASTYEAR(Sales[OrderDate].[Date])
)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
Example of use for SAMEPERIODLASTYEAR
Highlight
- Seasonal Trends
- Marketing Campaign Effectiveness
- Overall Business Health
Often used in retail and e-commerce for Year over Year comparisons.
Revenue YoY% Example
Revenue Yoy%=
VAR RevenuePreviousYear=
CALCULATE(
[Revenue], //Measure
SAMEPERIODLASTYEAR(Sales[OrderDate].[Date])
)
RETURN
DIVIDE([Revenue]-RevenuePreviousYear, RevenuePreviousYear)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
PARALLELPERIOD syntax
PARALLELPERIOD(DateColumn, NumberIntervals, UnitOfTime)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
Example of using PARALLELPERIOD
Compare this year’s sales with those from two years ago.
How does DATEADD work?
Returns a column of dates either added forward or backward in time by the specified number of intervals in the current context.
DATEADD Syntax
DATEADD(DateColumn,
NumberOfIntervals, Interval)
For example, the interval could be the year, quarter or month.
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
What does putting - in front of DATEADD do?
Subtracts the interval. Otherwise the default is to add the interval.
DATEADD Example
Sales Comparison=
CALCULATE(
[Revenue], //Measure
DATEADD(Sales[OrderDate].[Date], -1, MONTH)
)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
PREVIOUSYEAR syntax
PREVIOUSYEAR(DateColumn, Optional YearEndDate)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
Where is the PREVIOUSYEAR function instrumental?
When making Y-o-Y (Year Over Year) comparisons.
What are two related functions to PREVIOUSYEAR?
- PREVIOUSMONTH
- PREVIOUSQUARTER
- PREVIOUSDAY
What do the PREVIOUSDAY, PREVIOUSMONTH, PREVIOUSQUARTER and PREVIOUSYEAR functions do?
They return:
1. All dates in the previous year
2. Previous Day
3. Previous Month
4. Previous Quarter
What are PREVIOUSDAY, PREVIOUSMONTH, PREVIOUSQUARTER and PREVIOUSYEAR used for?
Historical evaluation of data
NEXTYEAR syntax
NEXTYEAR(DateColumn, YearEndDate)
You MUST have a date dimension table with a column of dates for time intelligence functions to work correctly.
What are three other functions similar to NEXTYEAR?
- NEXTDAY
- NEXTMONTH
- NEXTQUARTER
Where are the NEXT functions used?
- Projections
- Forecasts
Example using NEXTMONTH
Use NEXTMONTH to project if you’re on track to meet next months goals based on the current month’s data.