Forum Discussion

TimmK's avatar
TimmK
Helper IV
3 years ago
Solved

How to Dynamically Subtract Variable Days?

For simplicity I have a table with the three columns "Order Key", "Date" and "Days".   I would like to use a DAX measure (or if this is not possible a calculated column) to subtract the days from t...
  • johnt75's avatar
    3 years ago

    You could create a measure like

    Adjusted date =
    VAR ReferenceDate =
        SELECTEDVALUE ( 'Table'[Date] )
    VAR ReferenceDays =
        SELECTEDVALUE ( 'Table'[Days] )
    VAR BaseDate = ReferenceDate - ReferenceDays
    VAR Result =
        SWITCH ( WEEKDAY ( BaseDate ), 1, BaseDate - 2, 7, BaseDate - 1, BaseDate )
    RETURN
        Result