Forum Discussion

Aaron1's avatar
Aaron1
Frequent Visitor
8 years ago
Solved

Help with YOY DAX Calculation with Filter

Hi , I am having trouble figuring out how to make the calculation below bring back the correct YOY values.   In my data set i data from 2015, 2016 and 2017 but want to only show data from 2017 in ...
  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi Aaron1,

     

    Maybe you can try to use below formula:

    Amount YoY =
    VAR _current =
        SELECTEDVALUE ( 'Data'[Date] )
    VAR __PREV_YEAR =
        CALCULATE (
            SUM ( 'Data'[Amount] ),
            FILTER (
                ALL ( Data ),
                [Date]
                    >= DATE ( YEAR ( _current ) - 1, MONTH ( _current ), DAY ( _current ) )
                    && [Date] <= _current
            )
        )
    RETURN
        IF (
            ISFILTERED ( Data[Date] ),
            ERROR ( "Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column." ),
            SUM ( 'Data'[Amount] ) - __PREV_YEAR
        )
    

    Notice: all function will break filter effect, if you enable it on table, current filter will be ignored, you need to manually add filter conditions to apply filter effect.

     

     

    Regards,

    Xiaoxin Sheng