cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Alisea_MI
Resolver I
Resolver I

Time Intelligence calculation in weeks same period Current Year / Previous Year

Hi,

 

I need to set up calculations for the chosen period (last 13 weeks, last 26 weeeks, last 52 weeks) for the Current year and the same period for the previous year. Please note, that the period includes only full weeks, e.g. if today it is October, 7 2021, my "last 13 weeks period" for current year is from October ,1 2021 - July 5, 2021.  Invoice Date in my data set start with the last day of my current period, that is October, 1 2021.

 

I an trying to set it up using day granulatrity, since there's no week calculation (as far as I know).

 

The formula below works well for the current year:

CY =

var _start = MAX('Date'[Date])
var selected= SELECTEDVALUE('Period Parameter'[Period])
var period = IF(selected="Last 13 weeks",(13*7), IF(selected="Last 26 weeks", (26*7), IF(selected="Last 52 weeks", (52*7),9999)))
return CALCULATE(sum('InvoiceFact'[QuantityKFP]), DATESINPERIOD('Date'[Date], _start, -period, DAY))

 

Would really appreciate some help on setting it up for the same priod in previous year. For reference, my expected period for the last 13 weeks for previous year is: October, 2 2020 to July, 6 2020.

 

Thank you so much in advance!

 

1 ACCEPTED SOLUTION

Thanks, @AlexisOlson! The year has shifted to 2020, however, it took the whole October in 2020. What I needed was to shift today 1 year back, then start with the full week, before the "current date LY".

I have tested doing separate calculation for the current date LY,  start and end date and a calculation that calculates the chosen period for the previous year. It works fine. Publish my formulas below, in case someone else is looking for a similar solution.

 

Current Date LY = DATE(YEAR(MAX('Date'[Date]))-1, MONTH(MAX('Date'[Date])), DAY(MAX('Date'[Date])))
 
Start Date =
VAR _SelectedValue = SELECTEDVALUE('Period Parameter'[Period])
VAR _RESULT =
IF(_SelectedValue = "Last 52 weeks",
DATE(YEAR([End Date])-1,MONTH([End Date]),DAY([End Date])+1),
DATE(YEAR([End Date]),MONTH([End Date]),DAY([End Date])-'Period Parameter'[PeriodSelectedValue]))
RETURN DATE(YEAR(_RESULT),MONTH(_RESULT),DAY(_RESULT)+1)

 

End Date =
VAR _DAYNUM =WEEKDAY('Beräknade mätvärden'[Current Date LY],2)
VAR _END = DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
VAR _DATE =
SWITCH(
TRUE(),
[PeriodSelectedValue] = 91,_DAYNUM,
[PeriodSelectedValue] = 182,_DAYNUM,
[PeriodSelectedValue] = 365, _DAYNUM)
RETURN DATE(YEAR(_END),MONTH(_END),DAY( _END-_DAYNUM))

 

KFPInSelectedValue PY =
var DaysToday = WEEKDAY(TODAY(), 1)
var selected= SELECTEDVALUE('Period Parameter'[Period])
var period = IF(selected="Last 13 weeks",(13*7)+ DaysToday, IF(selected="Last 26 weeks", (26*7) + DaysToday, IF(selected="Last 52 weeks", (52*7)+ DaysToday,9999)))
return CALCULATE(sum('InvoiceFact'[QuantityKFP]), DATESBETWEEN('Date'[Date],[Start Date],[End Date]))

View solution in original post

3 REPLIES 3
AilleryO
Solution Sage
Solution Sage

Hi,

 

Sorry if it sounds silly, but did you try SAMEPERIODLASTYEAR ? or PARALLELPERIOD ?

Let us know...

 

AlexisOlson
Super User
Super User

Try shifting your dates argument back a year.

DATEADD ( DATESINPERIOD ( 'Date'[Date], _start, - period, DAY ), -1, YEAR )

Thanks, @AlexisOlson! The year has shifted to 2020, however, it took the whole October in 2020. What I needed was to shift today 1 year back, then start with the full week, before the "current date LY".

I have tested doing separate calculation for the current date LY,  start and end date and a calculation that calculates the chosen period for the previous year. It works fine. Publish my formulas below, in case someone else is looking for a similar solution.

 

Current Date LY = DATE(YEAR(MAX('Date'[Date]))-1, MONTH(MAX('Date'[Date])), DAY(MAX('Date'[Date])))
 
Start Date =
VAR _SelectedValue = SELECTEDVALUE('Period Parameter'[Period])
VAR _RESULT =
IF(_SelectedValue = "Last 52 weeks",
DATE(YEAR([End Date])-1,MONTH([End Date]),DAY([End Date])+1),
DATE(YEAR([End Date]),MONTH([End Date]),DAY([End Date])-'Period Parameter'[PeriodSelectedValue]))
RETURN DATE(YEAR(_RESULT),MONTH(_RESULT),DAY(_RESULT)+1)

 

End Date =
VAR _DAYNUM =WEEKDAY('Beräknade mätvärden'[Current Date LY],2)
VAR _END = DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
VAR _DATE =
SWITCH(
TRUE(),
[PeriodSelectedValue] = 91,_DAYNUM,
[PeriodSelectedValue] = 182,_DAYNUM,
[PeriodSelectedValue] = 365, _DAYNUM)
RETURN DATE(YEAR(_END),MONTH(_END),DAY( _END-_DAYNUM))

 

KFPInSelectedValue PY =
var DaysToday = WEEKDAY(TODAY(), 1)
var selected= SELECTEDVALUE('Period Parameter'[Period])
var period = IF(selected="Last 13 weeks",(13*7)+ DaysToday, IF(selected="Last 26 weeks", (26*7) + DaysToday, IF(selected="Last 52 weeks", (52*7)+ DaysToday,9999)))
return CALCULATE(sum('InvoiceFact'[QuantityKFP]), DATESBETWEEN('Date'[Date],[Start Date],[End Date]))

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors