Forum Discussion
gianma78
2 years agoFrequent Visitor
Help with Weighted Moving Average for delay delivery
Dear Community, hope you can assist. I am struggling with finding the correct way to calculate in Power Bi the Weighted Moving Average for delay delivery. Here is the case, assuming that we are ru...
gianma78
2 years agoFrequent Visitor
Hi Ryan,
apologies for the late reply, really sorry for that.
Please see below a better example:
I would like to calculate in DAX the weighted moving average of last 6 periods:
avg=(M1*1+M2*2+M3*3+M4*4+M5*5+M6*6)/21
(M1: 6 months ago, M2: 5 months ago, M3: 4 months ago, ..., M6: previous month).
Each month can have no feedback, one feedback or more.
Therefore I need first aggregate the feedback received per month and average them.
Expected result is below
| wt | Row Labels | Average of Feedback | wma |
| 1 | Jan-22 | 8.00 | |
| 2 | Feb-22 | 10.00 | |
| 3 | Apr-22 | 9.00 | |
| 4 | Aug-22 | 10.00 | |
| 5 | Sep-22 | 10.00 | |
| 6 | Oct-22 | 9.00 | 9.48 |
| Nov-22 | 10.00 | 9.67 | |
| Dec-22 | 3.00 | 7.76 | |
| Feb-23 | 10.00 | 8.19 | |
| Aug-23 | 7.50 | 7.86 | |
| Sep-23 | 8.00 | 7.79 | |
| Oct-23 | 9.00 | 8.10 | |
| Jan-24 | 2.00 | 6.40 | |
| Feb-24 | 8.00 | 6.81 | |
| Mar-24 | 10.00 | 7.55 | |
| Apr-24 | 9.00 | 8.00 | |
| May-24 | 9.00 | 8.38 | |
| Jun-24 | 9.67 | 8.90 |
where wma is =SUMPRODUCT(C2:C78,$A$2:$A$7)/SUM($A$2:$A$7)
I have tried this solution, but it does not return expected result
Test_wma =
var current_month = MAX('Feedback'[Date])
var m1 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = edate (current_month,-1))
var m2 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = EDATE(current_month, -2))
var m3 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = EDATE(current_month, -3))
var m4 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = EDATE(current_month, -4))
var m5 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = EDATE(current_month, -5))
var m6 =
CALCULATE(AVERAGE('Feedback'[Rating]), 'Feedback'[Date] = EDATE(current_month, -6))
var wma = ((m6 * 1) + (m5 * 2) + (m4 * 3 ) + (m3 * 4 ) + (m2 * 5) + (m1 * 6)) /21
RETURN wma
Any suggestion is highly appreciated!
Many thanks!
Ashish_Mathur
2 years agoSuper User
Hi,
PBI file attached.
Hope this helps.