Forum Discussion
Cumulative Stacked Line Chart - YoY by Month
Hi biotechanalyst ,
It sounds like you are using the same measure for the previous years and the current year, but the measure is only designed to work for the current year. To fix this issue, you can create separate measures for each of the years, and use a different filter for each measure to only include invoices up to the end of that year. For example, the measure for the current year could use the following code:
YTD Cumulative GBP =
CALCULATE (
[YTD GBP Spend],
FILTER (
ALLSELECTED ( 'Vendor Spend Summary' ),
'Vendor Spend Summary'[Invoice Date]
<= MAX ( 'Vendor Spend Summary'[Invoice Date] )
)
)
For the previous year, you would use a similar measure, but with a filter that only includes invoices up to the end of the previous year. For example:
PY Cumulative GBP =
CALCULATE (
[PY GBP Spend],
FILTER (
ALLSELECTED ( 'Vendor Spend Summary' ),
'Vendor Spend Summary'[Invoice Date]
<= MAX ( 'Vendor Spend Summary'[Invoice Date] - 1, [Invoice Date].[Year] )
)
)
This measure uses the MAX function to find the maximum invoice date for the previous year, and then filters the table to only include invoices up to that date. This will give you the cumulative total for the previous year, without including any invoices from the current or future years. You can use a similar approach for the previous previous year (PPY) as well.
By the way, you can provide test data refer to below link:
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- biotechanalyst3 years agoFrequent Visitor
For the PY measure, is there a different way to filter that only includes invoices for this year? Im having trouble making this calculation work in the model.
<= MAX ( 'Vendor Spend Summary'[Invoice Date] - 1, [Invoice Date].[Year] )
I do not have the ability to select "[Invoice Date]. [Year]"
For the [PY GBP Spend] Measure, I use a filter like this that only sums invoices for that year (2021), and works in the table (column PY GBP)
PY GBP = CALCULATE([GBP Spend],FILTER('Vendor Spend Summary',YEAR('Vendor Spend Summary'[Invoice Date])=(Year(TODAY())-1)))