Forum Discussion
Issue with TotalYTD and Sameperiodelastyear
Hi
I struggled with the "Function SAMEPERIODLASTYEAR expects a contiguous selection" error and found a lot of help on this site, but have a new issue. For some reason the formula for last year returns this years value.
Heres my setup.
- I have a datatable with a date/time column called InvoiceDate.
- I have created a calendar table with the following expression Dates = CALENDAR(DATE(2012;1;1) ; DATE(2025;12;31))
- The Dates table has a 1-many relationsship with the Datatable InvoiceDate column in the model view
- I use the following measures:
- TotalSales = SUM('mi_prd_datamarts fact_sales_statistics'[invoiced_amount_tcur])
- TotalSales YTD = TOTALYTD([TotalSales];'mi_prd_datamarts fact_sales_statistics'[InvoiceDate])
- TotalSales LYTD = CALCULATE([TotalSales YTD];SAMEPERIODLASTYEAR('Dates'[Date]))
For some reason TotalSales YTD and TotalSales LYTD both give me the actual 2018 YTD figures.
Before i introduced the Dates table the calculations were correct on a high level but I got the "contiguous" error when drilling down to lower levels.
Any help is appreciated, thanks in advance.
That solved the problem. I now get the values I want.
Thank you.
The set-up is now as follows:
Totalsalg YTD = TOTALYTD([Totalsalg];DATESYTD(Dates[Date]))
Totalsalg LYTD = CALCULATE([Totalsalg YTD];SAMEPERIODLASTYEAR('Dates'[Date]))
And I needed something to filter the year. Both a slicer that selects year or a matrix with year as rows works and gives me the YTD values. When adding a slicer that select Month of Year to-from I also get the eyar to date values from previous years.
20 Replies
- sokg
Solution Supplier
The ploblem is that you have to use date from calendar and not from invoice table
TotalSales YTD = TOTALYTD([TotalSales];'mi_prd_datamarts fact_sales_statistics'[InvoiceDate])
so change
TotalSales YTD = TOTALYTD([TotalSales];Dates[date])