Hi @Dharma,
The extended date table makes this childs play, when using offsets. Instead of hard coding Offset values I’ve added a What if parameter, CompareWeeks.
.
Created simple measures to harvest MIN and MAX Values but also setting Defaults.
CompareWeeks Min =
COALESCE(
MIN('CompareWeeks'[CompareWeeks]),
-3
)
CompareWeeks Max =
COALESCE(
MAX('CompareWeeks'[CompareWeeks]),
0
)
.
Added a conditional Count measure
Count =
VAR StartVal = [CompareWeeks Min]
VAR EndVal = [CompareWeeks Max]
VAR WeekRange = GENERATESERIES( StartVal, EndVal, 1 )
VAR WeeksWithLineage = TREATAS( WeekRange, Dates[WeekOffset] )
VAR Result =
IF( COUNTROWS( FILTER( Dates, Dates[WeekOffset] IN WeeksWithLineage )) >0,
COUNTROWS('Sample' )
)
RETURN
Result
and a perc change measure
% Change =
VAR StartVal = [CompareWeeks Min]
VAR EndVal = [CompareWeeks Max]
VAR WeekRange = GENERATESERIES( StartVal, EndVal, 1 )
VAR WeeksWithLineage = TREATAS( WeekRange, Dates[WeekOffset] )
VAR Result =
IF( COUNTROWS( FILTER( Dates, Dates[WeekOffset] IN WeeksWithLineage )) >0,
DIVIDE(
[Count],
CALCULATE( [Count], DATEADD( Dates[Date], -7, DAY ))
)
)
RETURN
IF( MAX( Dates[WeekOffset] ) <> StartVal && HASONEVALUE( Dates[Fiscal Year & Week] ),
Result
)
.
Now you can select Week & Year, WeekOffset or StartOfWeek as column attribute and the period will update dynamically as soon as you refresh the Dates table in the model. You can manually adjust the column width for the first % Change and Total % Change column making them invisible, just disable word wrap in the matrix settings.
.
Here’s your sample file.
eDNA - perc change last two weeks.pbix (101.3 KB)
I hope this is helpful