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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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