Forum Discussion

Nanakwame's avatar
Nanakwame
Icon for Helper II rankHelper II
4 years ago
Solved

Dax Function to Calculate same day last year

Hi All,   I have a function calculating sales yesterday which is  Sales Yesterday = CALCULATE(SUM(Sales[salesamount]),'Date'[Date] = TODAY() -1).    I am looking to also calculate the sales for...
  • AlexisOlson's avatar
    4 years ago

    There are a variety of ways to do this but the most straightforward might be to compute the date explicitly.

    Sales Yesterday LY =
    VAR _Y = TODAY () - 1
    VAR _YLY = DATE ( YEAR ( _Y ) - 1, MONTH ( _Y ), DAY ( _Y ) )
    RETURN
        CALCULATE ( SUM ( Sales[salesamount] ), 'Date'[Date] = _YLY )

    Note: I'm not sure if this would work if yesterday were a leap day.