Forum Discussion
Follow up on Previous Year Measure Issue
- 1 year ago
Hi TotalAnonymous,
Thank you for reaching out to Microsoft Fabric Community.
Thank you for sharing the pbix file, based on your requirement please replace your Offtake Sales – YTD PY measure with this below measure
Offtake Sales – YTD PY =
VAR LatestWeekID_ThisYear =
CALCULATE(
MAX('Sample Data'[WeekID]),
'calendar_new'[Year] = YEAR(TODAY())
)
VAR TargetWeekNumber =
MOD(LatestWeekID_ThisYear, 100)
VAR TargetYear = YEAR(TODAY()) - 1
VAR MinWeekID = TargetYear * 100 + 1
VAR MaxWeekID = TargetYear * 100 + TargetWeekNumber
RETURN
CALCULATE(
SUM('Sample Data'[Sales Value]),
FILTER(
ALL('Sample Data'),
'Sample Data'[WeekID] >= MinWeekID &&
'Sample Data'[WeekID] <= MaxWeekID
)
)
This will return YTD value of previous year up to 202418
Attached pbix file for your reference
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thanks and regards,
Anjan Kumar Chippa
Hi TotalAnonymous,
Thank you for reaching out to Microsoft Fabric Community.
Thank you for sharing the pbix file, based on your requirement please replace your Offtake Sales – YTD PY measure with this below measure
Offtake Sales – YTD PY =
VAR LatestWeekID_ThisYear =
CALCULATE(
MAX('Sample Data'[WeekID]),
'calendar_new'[Year] = YEAR(TODAY())
)
VAR TargetWeekNumber =
MOD(LatestWeekID_ThisYear, 100)
VAR TargetYear = YEAR(TODAY()) - 1
VAR MinWeekID = TargetYear * 100 + 1
VAR MaxWeekID = TargetYear * 100 + TargetWeekNumber
RETURN
CALCULATE(
SUM('Sample Data'[Sales Value]),
FILTER(
ALL('Sample Data'),
'Sample Data'[WeekID] >= MinWeekID &&
'Sample Data'[WeekID] <= MaxWeekID
)
)
This will return YTD value of previous year up to 202418
Attached pbix file for your reference
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thanks and regards,
Anjan Kumar Chippa
My code is the following
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thanks and regards,
Francesco Bergamaschi
- TotalAnonymous1 year agoHelper III
Hi FBergamaschi , thanks for your suggestion. Please allow me to test it first and will come back to you ASAP