Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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...
  • AllisonKennedy's avatar
    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))
    RETURN
    CALCULATE([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???