Forum Discussion
Last Year This/Same Week
- Anonymous9 years ago
How is [Week Year ID] stored? Could you build last years [Week Year ID] by making use of the same one you used in your TWTY measure?
For Example if [Week Year ID] is YYYYWW you could build the string using a combination of LEFT and RIGHT to get the Year and Week components, then decrement the YYYY by one and build a new filter string from there.
ooo, that is a clever approach.
It is stored as an INT (Whole number), download link below:
That said, all I need to do is change the Year Week ID to the format you proposed and I should be able to implement that approach.
Going to try now, I have not tried to use LEFT/RIGHT into a Measure before, let me give it a go and I will post back.
Since there are no PREVIOUSWEEK function in DAX.
So if need to get last year same week, you need to calculate the Year and week and weektotal in your data model, and then use LOOKUPVALUE function to get previous week value and last year same week value.
I have two tables in my sample data model. In your date table, create two columns.
Year = YEAR('Date'[CalendarDate])
WeekNumber = WEEKNUM('Date'[CalendarDate])
then create a new table
Table = SUMMARIZE('Date','Date'[Year],'Date'[WeekNumber],"
Create three measures.
WeekTotalSaleAmount = calculate(SUM(Sales[SalesAmount]),ALLEXCEPT('Date'
PreviousWeek = LOOKUPVALUE('Table'[Weektotal],'Table'[Year],IF(MA
PreviousYearWeek = LOOKUPVALUE('Table'[Weektotal],'Table'[Year],MAX('
Regards,
Charlie Liao
- Anonymous7 years agoNot applicable
This solution works great, but I have a newbie question. How would you adapt it to add in a category. For example I would like the PreviousYearWeek to return the number of Bikes sold the same week last year and the number of balls. Right now it seems to total my groups by week.