Forum Discussion
bradbel
8 months agoFrequent Visitor
SAMEPERIODLASTYEAR and Week Number Groupings/Calculations Not Returning Expected Result
I am currently trying to set up a bar and line chart showing CY and PY sales data, grouped into week numbers on the X axis. The issue is that the SAMEPERIODLASTYEAR function is returning the incorrec...
- 8 months ago
Hi bradbel ,
Try below:
PY Sales (Week Match) = VAR CurrentWeekNum = SELECTEDVALUE('Date'[WeekNum]) VAR CurrentYear = SELECTEDVALUE('Date'[Year]) RETURN CALCULATE( [Total Sales], ALL('Date'), -- Remove existing filters 'Date'[Year] = CurrentYear - 1, 'Date'[WeekNum] = CurrentWeekNum -- Forces Week 1 to match Week 1, ignoring 53rd weeks )this forces you to go to last year and apply the same weekfilter.
Please give kudos or mark it as solution once confirmed.
Thanks and Regards,
Praful
Praful_Potphode
8 months agoSuper User
Hi bradbel ,
Try below:
PY Sales (Week Match) =
VAR CurrentWeekNum = SELECTEDVALUE('Date'[WeekNum])
VAR CurrentYear = SELECTEDVALUE('Date'[Year])
RETURN
CALCULATE(
[Total Sales],
ALL('Date'), -- Remove existing filters
'Date'[Year] = CurrentYear - 1,
'Date'[WeekNum] = CurrentWeekNum -- Forces Week 1 to match Week 1, ignoring 53rd weeks
)this forces you to go to last year and apply the same weekfilter.
Please give kudos or mark it as solution once confirmed.
Thanks and Regards,
Praful
- bradbel8 months agoFrequent Visitor
This is incredible - solution verified, data now aligns exactly how I wanted it to. Thank you so much for the quick response!