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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ffan
Regular Visitor

Weighted Moving Average

Hi,

 

I am currently migrating an Excel report over to PowerBi.

 

Currently, my chart has an x axis being the beginning date of each calendar week.

 

Each point is populated by a weighted moving average of the last 4 weeks.

 

My formula is Sumproduct: [last 4 data points, count of last 4 data points/ count of last 4 data points].

 

How would I code this in PowerBi?

 

Thank you

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @ffan

Assume your dataset has "date" and " data points" column as below, then I create columns to define which is the beginning date per week.

1.png

weekday = WEEKDAY([date],1)

weeknum = WEEKNUM([date])

beginning date each week = CALCULATE(MIN([date]),ALLEXCEPT(Sheet1,Sheet1[weeknum]))

Each point is populated by a weighted moving average of the last 4 weeks.

As known

Weighted MA(4) = Ft+1 = wt1(Dt) + wt2(Dt-1) + wt3(Dt-2)+wt4(Dt-3)

for my example dataset from 2018/6/1~2018/8/13, it is from week 22 to week 33, so a weighted moving average of the last 4 weeks should calculate for week 30,31,32,33.

Assume refers to total data per week,  wt refers to 0.1,0.2,0.3,0.4.

total data per week shoud be get from a calculated measure

total per week = CALCULATE(SUM(Sheet1[data points]),FILTER(ALL(Sheet1),[weeknum]=SELECTEDVALUE(Sheet1[weeknum])))

2.png

 

Till now, I have doubt which is your  and wt refer to, and whether my understanding above is correct, please let me know more.

Besides, which does the formula mean?

[last 4 data points, count of last 4 data points/ count of last 4 data points]

 

Best Regards

maggie

 

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @ffan

Did my solution solve your problem?

If not, please don't hesitate to ask me.

 

Best Regards

Maggie

v-juanli-msft
Community Support
Community Support

Hi @ffan

Assume your dataset has "date" and " data points" column as below, then I create columns to define which is the beginning date per week.

1.png

weekday = WEEKDAY([date],1)

weeknum = WEEKNUM([date])

beginning date each week = CALCULATE(MIN([date]),ALLEXCEPT(Sheet1,Sheet1[weeknum]))

Each point is populated by a weighted moving average of the last 4 weeks.

As known

Weighted MA(4) = Ft+1 = wt1(Dt) + wt2(Dt-1) + wt3(Dt-2)+wt4(Dt-3)

for my example dataset from 2018/6/1~2018/8/13, it is from week 22 to week 33, so a weighted moving average of the last 4 weeks should calculate for week 30,31,32,33.

Assume refers to total data per week,  wt refers to 0.1,0.2,0.3,0.4.

total data per week shoud be get from a calculated measure

total per week = CALCULATE(SUM(Sheet1[data points]),FILTER(ALL(Sheet1),[weeknum]=SELECTEDVALUE(Sheet1[weeknum])))

2.png

 

Till now, I have doubt which is your  and wt refer to, and whether my understanding above is correct, please let me know more.

Besides, which does the formula mean?

[last 4 data points, count of last 4 data points/ count of last 4 data points]

 

Best Regards

maggie

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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