Hi guys, (my first post)
I’ve watched this youtube video (from SAM) about calculating last week sales, regarding the first week of the year. Awesome.
Net Revenue LW =
VAR CurrentWeek = SELECTEDVALUE(‘Main Calendar’[WeekN])
VAR CurrentYear = SELECTEDVALUE(‘Main Calendar’[Year])
VAR MaxWeekNum = CALCULATE(MAX(‘Main Calendar’[WeekN]), ALL(‘Main Calendar’))
RETURN
SUMX(
FILTER(All(‘Main Calendar’),
IF(CurrentWeek = 1,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 1 && ‘Main Calendar’[Year] = CurrentYear) ),
[T Net Revenues] )
I know that i should learn more about using nested IFs or SWITCH (TRUE() but i’m not sure if this the right approach for what i need which is, calculating a measure to calculate the sales of the week -2, another for week -3 and another week -4.
For example, the measure for the sales of 2 weeks before should be something like:
…
…IF(CurrentWeek = 1,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 1 && ‘Main Calendar’[Year] = CurrentYear) ),
IF(CurrentWeek = 2,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 2 && ‘Main Calendar’[Year] = CurrentYear) ),
and the sales for 3 weeks before…
…IF(CurrentWeek = 1,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 1 && ‘Main Calendar’[Year] = CurrentYear) ),
IF(CurrentWeek = 2,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 2 && ‘Main Calendar’[Year] = CurrentYear) ),
IF(CurrentWeek = 3,
‘Main Calendar’[WeekN] = MaxWeekNum && ‘Main Calendar’[Year] = CurrentYear -1,
‘Main Calendar’[WeekN] = CurrentWeek - 3 && ‘Main Calendar’[Year] = CurrentYear) ),
This measure’s not working of course and i’ve also tried with SWITH(TRUE().
Any one has any idea how to solve this?
Thanks in advance
Best regards
Pedro