Forum Discussion
Year to Date Percentage Change Calculation
- Anonymous2 years ago
Hi Anonymous
I made some changes to the code for the new table.
EarlyTotal = var CurrentYear = CALCULATE(MAX('Table'[Date]), ALL('Table')) var earlyMaxDate = CALCULATE(MAX('Table'[Date]), FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(CurrentYear) - 1 )) var EarlyYearTotal = CALCULATE( SUM('Table'[ Amount]), FILTER( ALL('Table'), YEAR('Table'[Date]) = YEAR(CurrentYear) - 1 && MONTH('Table'[Date]) = MONTH(earlyMaxDate) ) ) RETURN SUMMARIZE('Table', "EarlyYearTotal", EarlyYearTotal)You can check it out.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
This looks promising but I forgot to mention that my table includes data from months before December 2023 as well, my bad. Therefore, EarlyYearTotal returns the entire 2023 sales amount, not only December 2023, which breaks the YTD calculation for 2024.
Hi Anonymous
I made some changes to the code for the new table.
EarlyTotal =
var CurrentYear = CALCULATE(MAX('Table'[Date]), ALL('Table'))
var earlyMaxDate = CALCULATE(MAX('Table'[Date]), FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(CurrentYear) - 1 ))
var EarlyYearTotal =
CALCULATE(
SUM('Table'[ Amount]),
FILTER(
ALL('Table'),
YEAR('Table'[Date]) = YEAR(CurrentYear) - 1
&&
MONTH('Table'[Date]) = MONTH(earlyMaxDate)
)
)
RETURN SUMMARIZE('Table', "EarlyYearTotal", EarlyYearTotal)
You can check it out.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous2 years agoNot applicable
Anonymous Yes, this worked just fine, thanks a lot!