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
- FBergamaschi1 year ago
Super User
My code is the following
Offtake Sales - YTD PY =VAR MaxWeek = RIGHT ( CALCULATE( MAX ( 'Sample Data'[WeekID] ), REMOVEFILTERS() ), 2 )VAR Year=SELECTEDVALUE( calendar_new[Year] )VAR PY = Year-1VAR MaxWeekPY = PY&MaxWeekRETURNCALCULATE ([Offtake Sales - YTD],'Sample Data'[WeekID]<=INT(MaxWeekPY),DATEADD ( calendar_new[Date], -1, YEAR ))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 ago
Helper III
Hi FBergamaschi , thanks for your suggestion. Please allow me to test it first and will come back to you ASAP
- TotalAnonymous1 year ago
Helper III
Hi v-achippa , thanks for your suggestion. Please allow me to test it first from my end and come back to you ASAP
- v-achippa1 year ago
Community Support
Hi TotalAnonymous,
As we haven’t heard back from you, we wanted to kindly follow up to check if you have got any chance to test? Is the issue resolved?
If my response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.Thanks and regards,
Anjan Kumar Chippa
- v-achippa1 year ago
Community Support
Hi @TotalAnonymous,
We wanted to kindly follow up to check if you have got any chance to test? or Is the issue resolved?
If my response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.Thanks and regards,
Anjan Kumar Chippa