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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Newby_TCO_123
New Member

SAMEPERIODLASTYEAR not returning the correct amount

Hello,

 

I have 2 measures as follows:

CY Sales = 

Var CY = MAX('Date table'[Year])

return CALCULATE(SUM(Transactions[SalesAmnt], 'Date table'[Year] = CY)

and 

PY Sales = CALCULATE([CY Sales], SAMEPERIODLASTYEAR('Date table'[Date]))

but my PY returns the total sales for last year and not the sales for the same period as the current year.

 

What may be causing this?

 

Thanks,

Vlado

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Newby_TCO_123 Honestly, lots of things. I would recommend avoiding TI functions in DAX. I have some videos coming out in the next few weeks about these and how quirky they can be. This will help. To **bleep** With Time Intelligence - Microsoft Power BI Community. Specifically:

ToHellWithSAMEPERIODLASTYEAR = 
    VAR __NumIntervals = -1
    VAR __MaxDate = MAXX('Calendar',[Date])
    VAR __MinDate = MINX('Calendar',[Date])
    VAR __Start = __MinDate
    VAR __End = 
        SWITCH(TRUE(),
            __NumIntervals = 0 || __NumIntervals > 0,__MaxDate,
            IF(
                MONTH(__MaxDate) = 2 && DAY(__MaxDate) > 28,
                EOMONTH(__MaxDate,__NumIntervals*12),
                DATE(YEAR(__MaxDate) + __NumIntervals, MONTH(__MaxDate), DAY(__MaxDate))
            )
        )
RETURN
    FILTER('Calendar', [Date] >= __Start && [Date] <= __End)

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Newby_TCO_123 Honestly, lots of things. I would recommend avoiding TI functions in DAX. I have some videos coming out in the next few weeks about these and how quirky they can be. This will help. To **bleep** With Time Intelligence - Microsoft Power BI Community. Specifically:

ToHellWithSAMEPERIODLASTYEAR = 
    VAR __NumIntervals = -1
    VAR __MaxDate = MAXX('Calendar',[Date])
    VAR __MinDate = MINX('Calendar',[Date])
    VAR __Start = __MinDate
    VAR __End = 
        SWITCH(TRUE(),
            __NumIntervals = 0 || __NumIntervals > 0,__MaxDate,
            IF(
                MONTH(__MaxDate) = 2 && DAY(__MaxDate) > 28,
                EOMONTH(__MaxDate,__NumIntervals*12),
                DATE(YEAR(__MaxDate) + __NumIntervals, MONTH(__MaxDate), DAY(__MaxDate))
            )
        )
RETURN
    FILTER('Calendar', [Date] >= __Start && [Date] <= __End)

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.