Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 42 | |
| 18 | |
| 18 |
| User | Count |
|---|---|
| 69 | |
| 68 | |
| 32 | |
| 32 | |
| 32 |