Forum Discussion

KCfromDC's avatar
KCfromDC
Frequent Visitor
10 months ago
Solved

Hide previous years on x axis but keep average calculation

Hi all- I have a line graph with a count of items and a 5 year average (method here). I want to show a line graph of only the trends from the previous 5 years (e.g. count and then the average), but ...
  • MFelix's avatar
    MFelix
    10 months ago

    Hi KCfromDC ,

     

    Apologies for the incorrection I have done - 5 years on the formula and should be minus -4 years  to get current year + 4 that gives 5 years.

     

    If you do the math:

    105 + 136 + 123 + 90 +122 +107 = 683 / 6 = 113.83

     

    Redo the formula to:

    Notifications prev 5 years avg =
    VAR _TempTable =
        ADDCOLUMNS (
            CALCULATETABLE (
                VALUES ( 'Dates'[Year] ),
                REMOVEFILTERS ( 'Dates'[Year] )
            ),
            "Notifications", [Notifications count]
        )
    RETURN
        AVERAGEX (
            FILTER (
                _TempTable ,
                'Calendar'[Year] <= MAX ( 'Dates'[Year] )
                    && 'Calendar'[Year] >= MAX ( 'Dates'[Year] ) - 4
            ),
            [Notifications]
        )

     

    This should get expected result