Forum Discussion

Fusilier's avatar
Fusilier
Helper III
1 year ago
Solved

Replace divide by Average

I have this measure that calculates the previous 12 months by dividing by 12:

Rolling 12 Month Total avg = DIVIDE(CALCULATE (SUM ('Observation Type'[Reports]), DATESBETWEEN ('Observation Type'[Month], NEXTDAY (SAMEPERIODLASTYEAR (LASTDATE ('Observation Type'[Month]))), LASTDATE ('Observation Type'[Month]))),12)
 Is it possible to replace Divide by Average?
I tried this:
Rolling 12 Month Total avg 2 = AVERAGE(CALCULATE (SUM ('Observation Type'[Reports]), DATESBETWEEN ('Observation Type'[Month], NEXTDAY (SAMEPERIODLASTYEAR (LASTDATE ('Observation Type'[Month]))), LASTDATE ('Observation Type'[Month]))))
 
but that gives me an 'AVERAGE functiononly accepts a column reference as an arguement' error.
  • Hi Fusilier ,

    you need to iterate over the set of those 12 months and take an average of each month’s total:

     

    Instead of Average, try AverageX, like bellow

    Rolling 12-Month Avg =
    VAR LastMth    = LASTDATE( 'Observation Type'[Month] )
    VAR FirstMth   = NEXTDAY( SAMEPERIODLASTYEAR( LastMth ) )
    VAR MonthTable =
        DATESBETWEEN(
            'Observation Type'[Month],
            FirstMth,
            LastMth
        )
    RETURN
    AVERAGEX(
        MonthTable,
        CALCULATE( SUM( 'Observation Type'[Reports] ) )
    )

     

    Let me know if this help you.

     

    Thank you

  • Fusilier , Use Averagex

    DAX
    Rolling 12 Month Total avg 2 =
    AVERAGEX(
    DATESBETWEEN(
    'Observation Type'[Month],
    NEXTDAY(SAMEPERIODLASTYEAR(LASTDATE('Observation Type'[Month]))),
    LASTDATE('Observation Type'[Month])
    ),
    CALCULATE(SUM('Observation Type'[Reports]))
    )

2 Replies

  • Hi Fusilier ,

    you need to iterate over the set of those 12 months and take an average of each month’s total:

     

    Instead of Average, try AverageX, like bellow

    Rolling 12-Month Avg =
    VAR LastMth    = LASTDATE( 'Observation Type'[Month] )
    VAR FirstMth   = NEXTDAY( SAMEPERIODLASTYEAR( LastMth ) )
    VAR MonthTable =
        DATESBETWEEN(
            'Observation Type'[Month],
            FirstMth,
            LastMth
        )
    RETURN
    AVERAGEX(
        MonthTable,
        CALCULATE( SUM( 'Observation Type'[Reports] ) )
    )

     

    Let me know if this help you.

     

    Thank you

  • Fusilier , Use Averagex

    DAX
    Rolling 12 Month Total avg 2 =
    AVERAGEX(
    DATESBETWEEN(
    'Observation Type'[Month],
    NEXTDAY(SAMEPERIODLASTYEAR(LASTDATE('Observation Type'[Month]))),
    LASTDATE('Observation Type'[Month])
    ),
    CALCULATE(SUM('Observation Type'[Reports]))
    )