Last Updated: October 26, 2023
Time intelligence calculations are a powerful feature in DAX that allow you to analyze data over time. This document provides an in-depth guide to using DAX functions for common time-based analysis, such as year-to-date, month-over-month, and moving averages.
To effectively use time intelligence functions, you need to understand a few core concepts:
Calculate the cumulative sum of a measure from the beginning of the year to the current date.
Example: Calculate Total Sales YTD.
Total Sales YTD =
TOTALYTD(
SUM(Sales[SalesAmount]),
'Date'[Date]
)
Compare the current period's performance against the previous period (e.g., Previous Month, Previous Year).
Example: Sales Last Month.
Sales Last Month =
CALCULATE(
SUM(Sales[SalesAmount]),
PREVIOUSMONTH('Date'[Date])
)
Example: Sales Last Year.
Sales Last Year =
CALCULATE(
SUM(Sales[SalesAmount]),
SAMEPERIODLASTYEAR('Date'[Date])
)
Calculate the percentage change in sales compared to the previous period.
Example: Month-over-Month Sales Growth %.
MoM Sales Growth % =
DIVIDE(
SUM(Sales[SalesAmount]) - [Sales Last Month],
[Sales Last Month]
)
Calculate the average of a measure over a specified number of preceding periods.
Example: 3-Month Moving Average Sales.
3-Month Moving Avg Sales =
AVERAGEX(
DATESINPERIOD(
'Date'[Date],
LASTDATE('Date'[Date]),
-3,
MONTH
),
SUM(Sales[SalesAmount])
)
DAX offers a rich set of functions for manipulating dates and creating custom date periods.
DATESYTD(): Returns a table that contains a column of dates for the year to date, in the current context.DATESMTD(): Returns a table that contains a column of dates for the month to date, in the current context.DATESQTD(): Returns a table that contains a column of dates for the quarter to date, in the current context.DATEADD(): Returns a table containing a column of dates that are shifted a number of intervals before or after a specified starting date.Mastering time intelligence DAX functions is essential for creating insightful reports and dashboards that track performance trends and identify business patterns over time. By leveraging the functions and concepts discussed, you can unlock the full potential of your analytical data.