Forum Discussion

jackj's avatar
jackj
Helper I
4 years ago
Solved

Calculated Column for Previous Week Sales

Hi,   I am struggling to write dax for a calculated column, not a measure, that will provide me with the previous week's subtotal sales for a user id.  My data table is structured like this:   ...
  • AUaero's avatar
    4 years ago

    In that case you could rewrite the column to act as a binary flag.

    Prev Week Sales Flag = 
    VAR CurID = 'table'[UserID]
    VAR CurWeek = 'table'[Week Ending]
    VAR PrevWeek = CurWeek - 7
    
    VAR LastWeekSales = 
    CALCULATE(
        SUM('table'[Sales]),
        FILTER(
            ALL('table'),
            'table'[UserID] = CurID &&
            'table'[Week Ending] = PrevWeek
        )
    )
    
    RETURN
    SWITCH(
        TRUE(),
        LastWeekSales > 5, 1
        0
    )