Forum Discussion
Anonymous
5 years agoNot applicable
Measure for Previous year with custom date table
Hi al, I have a table with this years sales and last year sales on which I want to filter on both Month and Week. However the weeks are based on the ISO weeknumbers and I want to compare ISO week...
- 5 years ago
Hi Anonymous ,
Modify the measure as below:
Sales Last year = VAR CurrentWeek = SELECTEDVALUE ( 'Calendar'[ISO Week Number] ) VAR CurrentYear = SELECTEDVALUE ( 'Calendar'[Year] ) VAR currentMonth = SELECTEDVALUE ( 'Calendar'[MonthNum] ) RETURN IF ( NOT ( ISFILTERED ( 'Calendar'[Year] ) ), "You didnt select a year", IF ( ISFILTERED ( 'Calendar'[Year] ), IF ( ISFILTERED ( 'Calendar'[ISO Week Number] ) && NOT ( ISFILTERED ( 'Calendar'[MonthNum] ) ), CALCULATE ( [Sales], FILTER ( ALL ( 'Calendar' ), 'Calendar'[ISO Week Number] = CurrentWeek && 'Calendar'[Year] = CurrentYear - 1 ) ), IF ( ISFILTERED ( 'Calendar'[ISO Week Number] ) && ISFILTERED ( 'Calendar'[MonthNum] ), CALCULATE ( [Sales], FILTER ( ALL ( 'Calendar' ), 'Calendar'[ISO Week Number] = CurrentWeek && 'Calendar'[Year] = CurrentYear - 1 && 'Calendar'[MonthNum] = currentMonth ) ), IF ( NOT ( ISFILTERED ( 'Calendar'[ISO Week Number] ) ) && ISFILTERED ( 'Calendar'[MonthNum] ), CALCULATE ( [Sales], FILTER ( ALL ( 'Calendar' ), 'Calendar'[MonthNum] = currentMonth && 'Calendar'[Year] = CurrentYear - 1 ) ), IF ( NOT ( ISFILTERED ( 'Calendar'[ISO Week Number] ) ) && NOT ( ISFILTERED ( 'Calendar'[MonthNum] ) ), CALCULATE ( [Sales], FILTER ( ALL ( 'Calendar' ), 'Calendar'[Year] = CurrentYear - 1 ) ), BLANK () ) ) ) ) ) )And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
amitchandak
Super User
5 years agoAnonymous , Check if this can work
Sales Last year =
VAR CurrentWeek = maxx(allselected('Calendar'[), 'Calendar'[ISO Week Number] )
VAR CurrentYear = maxx(allselected('Calendar'[), 'Calendar'[Year] )
RETURN
CALCULATE( [Sales],
FILTER( ALL( 'Calendar' ),
'Calendar'[ISO Week Number] = CurrentWeek && 'Calendar'[Year] = CurrentYear - 1))
Anonymous
5 years agoNot applicable
Unfortunatly not. Selecting a Month gives wierd results. Weeks still works fine. Have another Idea?