Forum Discussion

enghone09's avatar
enghone09
Frequent Visitor
4 years ago
Solved

4 Years MAT calculation with YOY change

Hello everyone,   I have just started POWER BI and struggling to find a solution for moving annual total.   I currently have over 4 years of data from (01 Jan 2016 to 30 Jul 2021). and I would li...
  • ERD's avatar
    4 years ago

    Hi enghone09 ,

    From the example you've provided as far as I understand you need to achieve this:

    Measures:

    MATvalue = 
    VAR currentYear = MAX ( 'Date'[Year] )
    VAR latestDay = DAY ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
    VAR latestMonth = MONTH ( MAXX ( ALL ( T6[Date] ), T6[Date] ) )
    VAR MATDate = DATE ( currentYear, latestMonth, latestDay )
    VAR firstDay = EDATE ( MATDate + 1, -12 )
    RETURN
        CALCULATE (
            SUM ( T6[No. of Services] ),
            'Date'[Date] >= firstDay,
            'Date'[Date] <= MATDate
        )

    To have correct totals:

    MATresult = 
    IF (
        HASONEVALUE ( 'Date'[Year] ),
        [MATvalue],
        SUMX ( VALUES ( 'Date'[Year] ), [MATvalue] )
    )

    MAT%:

    MAT% = 
    VAR currentValue = [MATvalue]
    VAR previousValue = CALCULATE ( [MATvalue], DATEADD ( 'Date'[Date], -1, YEAR ) )
    RETURN
        IF (
            HASONEVALUE ( 'Date'[Year] ),
            DIVIDE ( currentValue - previousValue, previousValue ),
            BLANK ()
        )

    If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.