Forum Discussion
SAMEPERIODLASTYEAR WITH YTD
- 9 years ago
(I'm still pretty new at this myself but I encountered this situation)
I think your previous YTD is using the same context as the current YTD, or maybe you have a date filter on the whole matrix to report a specific year, so it isn't finding any data. Here is the thread with the problem I had and the solution.SAMEPERIODLASTYEAR with a year filter
What I ended up doing was this (this is from my own solution, I haven't tried to fit it to yours)
RevenueLastYTD = CALCULATE([RevenueYTD], FILTER(ALL(Dates), Dates[CalendarYear]=MAX(Dates[CalendarYear])-1), SAMEPERIODLASTYEAR(Dates[Date]))The key is using CALCULATE and FILTER. FILTER(ALL(Dates), ...) first opens up the dates context to use all dates again (because it may be currently set at a specific year, either because of a date filter on the whole matrix, or because of the row it is on). Then the next part of the filter statement sets a new filter for the previous year. I'm not entirely sure if that part is necessary since I'm calling SAMEPERIODLASTYEAR. I first did this several months ago and haven't worked with it much since then.
But take a look at using FILTER to open up the context in your previous year calculation.
Hi umpoohg
Try these measures:
Sales YTD = Calculate ( SUM('IHeads'[Sales] ) , DatesYtd( DateTable[Date] ) )
Sales YTD LY = Calculate ( [Sales YTD] , SamePeriodLastYear( DateTable[Date] ) )
You can also leverage DAX variables and embed them to compute Sales YTD LY:
Sales YTD LY 2 = VAR YTDTab = DatesYtd(DateTable[Date]) VAR YTDLYTab = SamePeriodLastYear( YTDTab ) RETURN
Calculate ( SUM('IHeads'[Sales]) , YTDLYTab )
Hi Datatouille,
Thank you for your response, however below are the results...so strange?!?!?!?!
Sales YTD = Calculate ( SUM('IHeads'[Sales] ) , DatesYtd( DateTable[Date] ) )
Sales YTD LY = Calculate ( [Sales YTD] , SamePeriodLastYear( DateTable[Date] ) )
Seems it is basically doing what the measures I have created are doing...