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!
Anonymous
5 years agoNot applicable
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-msft
Community Support
5 years agoHi 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,
Kelly
Did I answer your question? Mark my post as a solution!