Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gianma78
Frequent 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 running different project, and for each project we have expected delivery date. If that date is missed we have delay. Need now to calculate the weighted moving average for this delays in PBI.

Is that possible? 

Thanks for help!

 

6 REPLIES 6
gianma78
Frequent 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

wtRow LabelsAverage of Feedbackwma
1Jan-228.00 
2Feb-2210.00 
3Apr-229.00 
4Aug-2210.00 
5Sep-2210.00 
6Oct-229.009.48
 Nov-2210.009.67
 Dec-223.007.76
 Feb-2310.008.19
 Aug-237.507.86
 Sep-238.007.79
 Oct-239.008.10
 Jan-242.006.40
 Feb-248.006.81
 Mar-2410.007.55
 Apr-249.008.00
 May-249.008.38
 Jun-249.678.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!

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_1-1720846526523.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello @gianma78 , as @ryan_mayu has asked , please help with the following:

.
Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot). You can upload the PBIX file to a cloud storage service such as OneDrive, Google Drive, Dropbox, or to a Github repository, and then share a file’s URL.

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello Ryan, sorry for the late reply. In the meantime, requestor changed the specifics for this calc.

What we aim to obtain is the weighted moving average per scores, and the moving should be based on a fix amount of months (or rating received). 

Assuming the following example

Date of DeliveryProjectRating
06/2023P23_0017
06/2023P23_0025
08/2023P23_0039
09/2023P23_0048

12/2023

P23_005 
01/2024P24_0016
01/2024P24_0029

 

It is a sample of the table I have, I can calculate the moving average as following DAX

"CALC Rating Moving Avg =
VAR _max_date = ENDOFMONTH('Calendar'[Date])
VAR _min_date = EDATE(_max_date,-6)
VAR _avg = CALCULATE(AVERAGE('Projects Log '[Feedback]),'Calendar'[Date] > _min_date && 'Calendar'[Date] <= _max_date)
RETURN _avg "
 
Any chance to have the weighted moving avg to have more emphasys to the recent Project delivered (guess I need to create the table of weights which is rolling on monthly basis)? And, if no rate is received, then skip the project from calculation 
Any hint would be highly appreciated

what's the expected output basd on the sample data you provided?

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.