cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Helper III

## How to calculate measure for same period 2 years ago

Hi there,

I use SAMEPERIODLASTYEAR() to calculate measure for same period 1 year ago.

How do I do it for same period 2 years ago?

Thanks,

Wes

1 ACCEPTED SOLUTION
Super User

@wes-shen-poal measurename = calculate(measure, parallelperiod(datetable[date], -2, year))

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

9 REPLIES 9
New Member

I Just found a better way to do it + It work dynamically based on user selection (not just on Only Year or Month or Days)

I've just nested Sameperiodlastyear

So for same period 2 year ago it will be like :

Syntax : SAMEPERIODLASTYEAR(SAMEPERIODLASTYEAR([Date]))

Frequent Visitor

(edited)
I tried the suggested PARALLELPERIOD function and it skewed dates and values. You can test by just comparing the calc field with one year only using SAMEPERIODLASTYEAR and PARALLELPERIOD.

What has worked for me was DATEADD, so, the mesuare will look like:

This way at least you compare the "same weekday", could be not in the same month but that is what I was after. Use @Anonymous but with DATEADD() suggestion below for other usecases.

I know is 5 yrs ago the question, but worth the contribution!

Regards

Jose

Helper I

This was the one that worked for me!
My month selection in my slicer is dynamic, so this let me compare historical YTD numbers (parallelperiod would only give me prior full years)

Thanks!

Anonymous
Not applicable

Good to be mindful of what period type you have in your report.

If you want to see the whole of the year for two years ago then the  prior solution is perfect

calculate(measure, parallelperiod(datetable[date], -2, year))

However, if the report is a month by month one then try

calculate(measure, parallelperiod(datetable[date], -24, month))

Helper II

Hi, I have tried your advice but I'm getting the error message below. Can you tell me what I'm missing? Thanks!

Super User

Are you missing the DATEADD function?

Regards,
Ashish Mathur
http://www.ashishmathur.com
Anonymous
Not applicable

CALCULATE ([Net Sale TY], PARALLELPERIOD('Date'[Date], - 24,MONTH))

I think You need to include the PARALLELPERIOD function name and also a comma before the -24

Please let me know how you go

Super User

@wes-shen-poal measurename = calculate(measure, parallelperiod(datetable[date], -2, year))

If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!

Helper III

Thank you @vanessafvg

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors