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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Willborn
Advocate II
Advocate II

Going back 2 years instead only 1

Hi there

 

I'm using the SAMEPERIODLASTYEAR-Function. Is there a way to get the year bevor the previous year (2016 YTD + 2015 same period + 2014 same periode)?

 

Currently in use:

SaleP2YTot = CALCULATE([SaleTot]; SAMEPERIODLASTYEAR('Dates'[Date]))

Thanks for any input & Regards!

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

According to the documentation:

https://msdn.microsoft.com/en-us/library/ee634972.aspx

 

The dates returned are the same as the dates returned by this equivalent formula:

DATEADD(dates, -1, year)

 

So perhaps:

DATEADD(dates, -2, year)


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

According to the documentation:

https://msdn.microsoft.com/en-us/library/ee634972.aspx

 

The dates returned are the same as the dates returned by this equivalent formula:

DATEADD(dates, -1, year)

 

So perhaps:

DATEADD(dates, -2, year)


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you smoupre!

 

SalesP2YTot = CALCULATE([SalesTot]; DATEADD(Dates[Date]; -2; year))

 

Did not realized that I have to replace the "sameperiodlastyear"-Function. But it's working well.

 

What about when calculation the cummulative sales total? Can I use the same functionality like as:

 

CumSalesP2YTot = CALCULATE (
    [SalesPYTot];
    FILTER (
        ALLSELECTED(Dates);
        'Dates'[Date] <= DATEADD(Dates[Date]; -1; year)
            && 'Dates'[Date] <= TODAY()
    )
)

 

 

Regards Patrick

Greg_Deckler
Super User
Super User

According to the documentation:

https://msdn.microsoft.com/en-us/library/ee634972.aspx

 

The dates returned are the same as the dates returned by this equivalent formula:

DATEADD(dates, -1, year)

 

So perhaps:

DATEADD(dates, -2, year)


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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