Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi,
I'm having some troubles with my SAMEPERIODLASTYEAR calculations.
I'm trying to compare the first 3 days of March '26 against the same period for last year using SAMEPERIODLASTYEAR, but what I get is the total amount of March '25.
The formula I'm using is:
Sales Y-1 = CALCULATE(
Solved! Go to Solution.
HI ,
According to the DAX page, SAMEPERIODLASTYEAR function (DAX) - DAX | Microsoft Learn for Sameperiodlastyear, "For calendar inpu...
Proud to be a Datanaut!
Private message me for consulting or training needs.
Dears,
thank you all for your answer!
they made me realize that the mismatch was between the last day of Calendar Table (set using TODAY() ) and the last SalesDate available (today too since the report is daily refreshed). To me, adding one day to the calendar (TODAY()+1) did the trick, but I believe the DATEADD solutions is cleaner.
For explanation purposes, the filter I was using had day granularity
Hi @TT_newbie
That is the expected behaviour of SAMEPERIODLASTYEAR - it returns the whole year unless you add the day of month as a filter.
Value SPLY 2 =
VAR LatestDateWithValue =
CALCULATE (
LASTNONBLANK ( Dates[Date], [Sum of Value] ),
ALLSELECTED ( Dates[Date] )
) -- or TODAY()
VAR _MMDD =
FORMAT ( LatestDateWithValue, "MMDD" )
RETURN
CALCULATE (
[Sum of Value],
SAMEPERIODLASTYEAR ( Dates[Date] ),
KEEPFILTERS ( FORMAT ( Dates[Date], "MMDD" ) <= _MMDD )
)
Please see the attached pbix.
Hi,
Your formula is correct. Do one of the following:
@TT_newbie
Why you are getting full month instead of three days.
The issue is that your slicer is selecting the full month, so:
SAMEPERIODLASTYEAR shifts the full month.
To compare only first 3 days:
Use a date range slicer, add dates in there.
Proposed Solution:
Make sure your slicer filters exact dates (not full month).
Use this DAX formula instead of sameperiodlastyear, this is easy to debug.
Sales Y-1 =
CALCULATE (
SUM (SalesAnalysis [Sales Amount]),
DATEADD (Calendar [Date], -1, YEAR)
)
If this helps, ✓ Mark as Kudos | Mark as Solution| Help Others
HI ,
According to the DAX page, SAMEPERIODLASTYEAR function (DAX) - DAX | Microsoft Learn for Sameperiodlastyear, "For calendar inpu...
Proud to be a Datanaut!
Private message me for consulting or training needs.
| User | Count |
|---|---|
| 58 | |
| 45 | |
| 32 | |
| 16 | |
| 14 |
| User | Count |
|---|---|
| 82 | |
| 68 | |
| 43 | |
| 26 | |
| 25 |