Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
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
Solved! Go to Solution.
@wes-shen-poal measurename = calculate(measure, parallelperiod(datetable[date], -2, year))
Proud to be a Super User!
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]))
I am trying to calcualte the same period 2 years ago, but it is not working for me.
Can you share your example that is working.
Thanks,
pthapa
Hi pthapa,
What worked for me was using DATEADD. The measure looks like:
measureName =calculate(measure, DATEADD(datetable[date], -2*364, DAY)) This way work if you want to compare the "same weekday", since it could be not in the same month but that is what I was after.
Regards
Jose
(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:
measureName =calculate(measure, DATEADD(datetable[date], -2*364, DAY))
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
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!
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))
Hi, I have tried your advice but I'm getting the error message below. Can you tell me what I'm missing? Thanks!
Are you missing the DATEADD function?
Please try
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
@wes-shen-poal measurename = calculate(measure, parallelperiod(datetable[date], -2, year))
Proud to be a Super User!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
87 | |
87 | |
87 | |
67 | |
49 |
User | Count |
---|---|
135 | |
112 | |
100 | |
68 | |
67 |