Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next 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

Reply
TT_newbie
New Member

SAMEPERIODLASTYEAR not giving correct results

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(

SUMSalesAnalysis[Sales Amount] ),
SAMEPERIODLASTYEAR( Calendar[Date] )
)

 

I created the Calendar table and set it as Date table
Also, I've already tried adding ALL( Calendar[Date]) since I'm filtering the visual using a slicer with Calendar[Date] as data field; but that didn't work.
SalesAnalysis table is linked to the Calendar by SalesDate column
Thanks in advance for your help!
1 ACCEPTED SOLUTION
collinq
Super User
Super User

HI  ,

According to the DAX page, SAMEPERIODLASTYEAR function (DAX) - DAX | Microsoft Learn for Sameperiodlastyear, "For calendar inpu...



Sales Y-1 (Selected Range) :=
VAR MinDate = MIN ( Calendar[Date] )
VAR MaxDate = MAX ( Calendar[Date] )
RETURN
CALCULATE (
    SUM ( SalesAnalysis[Sales Amount] ),
    DATEADD (
        DATESBETWEEN ( Calendar[Date], MinDate, MaxDate ),
        -1,
        YEAR
    )
)

  

 

@TT_newbie




Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!
Private message me for consulting or training needs.




View solution in original post

5 REPLIES 5
TT_newbie
New Member

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

danextian
Super User
Super User

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 )
    )

danextian_0-1772622789912.png

Please see the attached pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ashish_Mathur
Super User
Super User

Hi,

Your formula is correct.  Do one of the following:

  1. Ensure that your Calendar goes only until today; or
  2. Create a Date slicer from the Calendar table and select the first 3 days.

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Murtaza_Ghafoor
Skilled Sharer
Skilled Sharer

@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

 

collinq
Super User
Super User

HI  ,

According to the DAX page, SAMEPERIODLASTYEAR function (DAX) - DAX | Microsoft Learn for Sameperiodlastyear, "For calendar inpu...



Sales Y-1 (Selected Range) :=
VAR MinDate = MIN ( Calendar[Date] )
VAR MaxDate = MAX ( Calendar[Date] )
RETURN
CALCULATE (
    SUM ( SalesAnalysis[Sales Amount] ),
    DATEADD (
        DATESBETWEEN ( Calendar[Date], MinDate, MaxDate ),
        -1,
        YEAR
    )
)

  

 

@TT_newbie




Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!
Private message me for consulting or training needs.




Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.