DAX Power BI: Time Frame of Analysis — Mastering DATEADD and SAMEPERIODLASTYEAR

Andrei Khaidarov, Microsoft MVP, PhD
Microsoft Power BI
Published in
2 min readDec 18, 2023

--

Let’s consider two types of functions for working with dates. The first type is the SAMEPERIODLASTYEAR function. This function is a special case of the DATEADD function. Let’s consider this function by example. For this purpose, let’s create a measure in which we need to calculate the expression for the same month but a year ago.

This is how such a problem is solved using the DATEADD function. Now let’s consider the solution of this problem using the SAMEPERIODLASTYEAR function.

The code of such a function is much smaller, it is enough to pass one argument to this function — the column by which the selection is performed.

Finally, we discussed two important types of functions for working with dates: DATEADD and SAMEPERIODLASTYEAR. Both functions offer unique ways to analyze temporal data, allowing users to easily compare performance over different time periods. When using DATEADD, flexibility in period selection can be achieved, while SAMEPERIODLASTYEAR offers a simpler and more straightforward solution for comparing data to the previous year. The choice between these functions depends on the specific needs of the analysis and the user’s preferences. These features are powerful tools in the hands of data analysts, allowing them to uncover valuable insights and trends hidden in temporal data.

Don’t forget to subscribe to

👉 Power BI Publication

👉 Power BI Newsletter

and join our Power BI community

👉 Power BI Masterclass

--

--

Andrei Khaidarov, Microsoft MVP, PhD
Microsoft Power BI

🎓 Microsoft Data Platform MVP | MCT | Power BI Super User | Global Power Platform Hero| Power Platform Solution Architect| Technical reviewer for Packt's books