Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

SAMEPERIODLASTYEAR Returns values for future date

I am using SAMEPERIODLASTYEAR to create a measure that returns last years sales values. However my Date Table also has future dates for forecasting purposes.   My question is how do i prevent the f...
  • rajendraongole1's avatar
    1 year ago

    Hi Anonymous -

    You're on the right track with using SAMEPERIODLASTYEAR, but the issue is that SAMEPERIODLASTYEAR still returns dates from the prior year, even when you're in a future month (with no current year data yet).

    To fix this, we need to ensure that the prior year values are only returned when the current period has actually occurred

     

    Prior Period Sales =
    VAR CurrentDate = MAX(DateTable[Date])
    RETURN
    IF (
    CurrentDate <= TODAY(), -- Only calculate for dates up to today
    CALCULATE(
    SUM(SalesData[Sales]),
    SAMEPERIODLASTYEAR(DateTable[Date])
    )
    )

     

    can you try this and confirm