Forum Discussion
Measure for Previous year with custom date table
- 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!
Hi Anonymous ,
After checking,if you have selected a year,then you wont see an error,so modify your measure as below:
Sales Last year =
VAR CurrentWeek = SELECTEDVALUE( 'Calendar'[ISO Week Number] )
VAR CurrentYear = SELECTEDVALUE( 'Calendar'[Year] )
RETURN
IF(ISFILTERED('Calendar'[Year]),
CALCULATE( [Sales],
FILTER( ALL( 'Calendar' ),
'Calendar'[ISO Week Number] = CurrentWeek && 'Calendar'[Year] = CurrentYear - 1)),
CALCULATE( [Sales],
FILTER( ALL( 'Calendar' ),
'Calendar'[ISO Week Number] = CurrentWeek && 'Calendar'[Year] =YEAR(TODAY()) - 1)))+0
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
v-kelly-msft I am Sorry that i am not clear enough but this measure still does not give me a result when only selecting a month.
I also want previous year sales when selection only a Monthnum and a Year:
- v-kelly-msft5 years ago
Community Support
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!