Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

SAMEPERIODLASTYEAR return a wrong result when the date is the last in the calendar

Hi Everyone, I hope you are doing well. I have a simple star schema model (a calendar dimension and a fact sales table). When I tried to calculate the MTD value last year with SAMEPERIODLASTYEAR, ...
  • wdx223_Daniel's avatar
    5 years ago

    Anonymous this might work

    _MTD_TC_PY = 
    VAR _END = MAX(DIM_CALENDAR[DATE])
    VAR _START = DATE(YEAR(_END), MONTH(_END), 1)
    RETURN CALCULATE([_TC], SAMEPERIODLASTYEAR(DATESMTD(DIM_CALENDAR[DATE])),DIM_CALENDAR[DATE]<=EDATE(_END,-12))