Forum Discussion
Anonymous
4 years agoNot applicable
DATEADD: Dynamic value for the interval parameter
I am trying to compare the current value of a measure against the previous period using DATEADD. CALCULATE(
[Sessions],
DATEADD( Dates[Date], -30 , DAY )
) I do not want the interv...
- 4 years ago
Anonymous You need to calculate the interval for ALLSELECTED dates, otherwise it will use the context of the visual you're calculating within.
This measure works:
Previous Period Sales =VAR Int = CALCULATE(DATEDIFF(MAX(Dates[Date]), MIN(Dates[Date]), DAY), ALLSELECTED(Dates))RETURNCALCULATE([Total Sales], DATEADD(Dates[Date], Int, DAY))Though be careful to name the visuals, etc well as it's confusing what it's showing when random periods are selected, might be best used with a relative date slicer only???
Anonymous
4 years agoNot applicable
Thank you so much AllisonKennedy! This worked brilliantly.
AllisonKennedy
4 years agoCommunity Champion
You're very welcome. Glad it worked.