Forum Discussion

DCWork's avatar
DCWork
New Member
1 year ago
Solved

Previous Year Calculation

Morning,

 

I have a calculation to show a date range of the previous Sunday-Saturdy.  Which I am using as a filter.  However I need to take same date range and show it for the previous year.  My Sun-Sat calc is:

 

_Is_Last_Week =
VAR TodayDate = TODAY()
VAR LastSaturday = TodayDate - WEEKDAY(TodayDate, 1)
VAR LastSunday = LastSaturday - 6
RETURN
IF(
'DimDate'[Date] >= LastSunday && 'DimDate'[Date] <= LastSaturday,
TRUE,
FALSE
)

 

Any thoughts on how to amend this for the same period last year?

 

Thanks

  • Hi DCWork  - you can simply shift the calculated LastSunday and LastSaturday back by 1 year using EDATE or DATEADD

     

    use the below measure:

    _Is_Last_Week_PY =
    VAR TodayDate = TODAY()
    VAR LastSaturday = TodayDate - WEEKDAY(TodayDate, 1)
    VAR LastSunday = LastSaturday - 6

    VAR LastSaturday_PY = EDATE(LastSaturday, -12)
    VAR LastSunday_PY = EDATE(LastSunday, -12)

    RETURN
    IF (
    'DimDate'[Date] >= LastSunday_PY &&
    'DimDate'[Date] <= LastSaturday_PY,
    TRUE,
    FALSE
    )

    Hope this helps.

2 Replies

  • Hi DCWork  - you can simply shift the calculated LastSunday and LastSaturday back by 1 year using EDATE or DATEADD

     

    use the below measure:

    _Is_Last_Week_PY =
    VAR TodayDate = TODAY()
    VAR LastSaturday = TodayDate - WEEKDAY(TodayDate, 1)
    VAR LastSunday = LastSaturday - 6

    VAR LastSaturday_PY = EDATE(LastSaturday, -12)
    VAR LastSunday_PY = EDATE(LastSunday, -12)

    RETURN
    IF (
    'DimDate'[Date] >= LastSunday_PY &&
    'DimDate'[Date] <= LastSaturday_PY,
    TRUE,
    FALSE
    )

    Hope this helps.

    • DCWork's avatar
      DCWork
      New Member

      that's great, thanks for that.