The approach to creating such a comparison will be using TOTALYTD for the current part of the year and SAMEPERIODLASTYEAR or DATEADD for last year's YTD numbers.
DAX Measures for YTD versus Previous YTD
1. Year to Date (YTD) Sales
Sales YTD = TOTALYTD( SUM( Sales[Revenue] ), 'Date'[Date] )
Incorporate TOTALYTD to derive the running total revenue from January 1 through the present date. Then, the data fact can be applied to any time intelligence.
2. Sales in the previous year YTD (using SAMEPERIODLASTYEAR)
Sales PY YTD =
CALCULATE(
[Sales YTD],
SAMEPERIODLASTYEAR( 'Date'[Date] )
)
The date span will be modified one year back, during a similar time period. This guarantees an accurate YTD comparison without manual adjustments.
Alternative: Previous Year YTD Using DATEADD.
Sales PY YTD (DATEADD) =
CALCULATE(
[Sales YTD],
DATEADD( 'Date'[Date], -1, YEAR )
)
If any custom shifts happen to be needed, such as for fiscal years, DATEADD gives flexibility.
Why this Approach?
Year-To-Date Calculations: Correctly accumulate totals throughout.
Works with Dynamic Filtering – Reacts with slicers and date selection.
Optimized for Performance – Efficient usage of out-of-the-box time-intelligence functions of Power BI.