Forum Discussion
SAMEPERIODLASTYEAR Returns values for future date
- 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
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
- Anonymous1 year agoNot applicable
Hi rajendraongole1,
Thank you for assisting with this. This works! Thank you very much. It appears that the Variable is required to define a date range first before moving onto the SAMEPERIODLASTYEAR component of the measure.