Forum Discussion

Ikigai's avatar
Ikigai
New Member
1 year ago
Solved

DATEADD function (DAX) for previous year by slicer

I have a dataset that starts in July 2023 and updates each month.  Lastest refresh is up to November 2024.  December 2024 is still needing to come in.  I am using the DATEADD measure to look at previ...
  • danextian's avatar
    1 year ago

    Hi Ikigai 

    Please try this:

    PreviousYear2 = 
    VAR FullYear =
        CALCULATE (
            [Total Revenue],
            FILTER ( ALL ( Dates ), Dates[Year] = MAX ( Dates[Year] ) - 1 )
        )
    VAR LastYear =
        CALCULATE ( [Total Revenue], DATEADD ( Dates[Date], -1, YEAR ) )
    VAR MonthSelectedTest =
        --test if allselected months less than all months
        COUNTROWS ( ALLSELECTED ( Dates[Month Short] ) ) < COUNTROWS ( ALL ( Dates[Month Short] ) )  
    RETURN
        --will return  the full last year if year if no period is selected
        IF ( MonthSelectedTest, LastYear, FullYear )
    

    Attached is a sample pbix