Skip to main content

Power BI

New

Moving average with QUick Measures

Vote (7) Share
's profile image

on 07 Apr 2017 23:15:12

Name:
Moving Average per category
Description:
Calculate the moving average of the base value within the category over 12 months
Parameters:
Name: Base value
Tooltip: The value over which you want to calculate the moving average over 12 months
Type: Numerical field / measure
 
Name: Date
Tooltip: The date filed used to calculate the average
Type: Date
DAX:
Moving Average {Base value} =
Amount MAVG Measure =
var sdate=EDATE('Table'[Date]); 11) // This is the month when to start displaying results (used below in IF) It is the lowest date + 11 months
var d = MAX('Table'[Date] ) // the current date from Table 'Table'
var d365 =EDATE(d;-12) // this calculates a date 12 months before the current date (i assume it works with leap years)
var r=
IF( d >sdate;
SUMX(
FILTER(ALL('Table'); 'Table'[Date] <= d && 'Table'[Date] > EDATE(d;-12) );
{Base value} )
/12
)
RETURN
r

From