Easiest DAX function to add a Last 7 Day marker column to a Calendar table

I have a Calendar table and would like to add a calculated column "Is Last 7 Days" - it should be either 1 or 0 - so if DayMarker is within the last 7 days it shows 1 ortherwise 0.

I have this DAX expression which seems over-complicated - what is the easy way?

Last 7 Days = 
IF(
    'Calendar'[DayMarker] >=
        MAXX(
            ALL('Calendar')
            , DATEADD('Calendar'[DayMarker],-7,DAY) 
            )
    ,1
    ,0
)

1 answer

  • answered 2018-03-13 22:00 Alexis Olson

    Try this:

    Last 7 Days = IF(MAX('Calendar'[DayMarker]) - 'Calendar'[DayMarker] < 7, 1, 0)
    

    If you prefer, you can use DATEDIFF instead of subtraction:

    Last7Days = IF(DATEDIFF('Calendar'[DayMarker], MAX('Calendar'[DayMarker]), DAY) < 7, 1, 0)