Moving Average

cunningAce

Board Regular
Joined
Dec 21, 2017
Messages
91
Office Version
  1. 365
Platform
  1. Windows
Hi,

Hoping someone could help me with the following please,

I am looking to find the average of a range of numbers (determined by the variable in the 'weeks average' cell)

So in the below examples, I want the average of the last 5 weeks for each set of numbers.
I want to ignore any zeros after the last weeks figures (week 8 in these examples) but include any zeros within the 5 week average,

Eg,
The first line would calculate an average for weeks 4-8 - (0,10,50,60,100 = 44)
The 3rd line would also calculate weeks 4-8 ignoring anything before, and any zeros after week 8. (5,10,50,60,200 = 65)

Hope this makes sense,


Thanks in advance,


BCDEFGHIJKL
3Week 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9Week 10Average
400001050601000044
500051050601000045
624651050602000065
7
8
9Weeks Average5

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

<tbody>
</tbody>

 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Book1
BCDEFGHIJKL
3Week 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9Week 10Average
400001050601000044
500051050601000045
624651050602000065
7
8
9Weeks Average5
Sheet2
Cell Formulas
RangeFormula
L4{=AVERAGE(OFFSET(B4:INDEX(B4:K4,LARGE(IF(B4:K4<>0,COLUMN(B4:K4)-COLUMN(B4)+1),1)),0,LARGE(IF(B4:K4<>0,COLUMN(B4:K4)-COLUMN(B4)+1),1)-$C$9,1,$C$9))}
L5{=AVERAGE(OFFSET(B5:INDEX(B5:K5,LARGE(IF(B5:K5<>0,COLUMN(B5:K5)-COLUMN(B5)+1),1)),0,LARGE(IF(B5:K5<>0,COLUMN(B5:K5)-COLUMN(B5)+1),1)-$C$9,1,$C$9))}
L6{=AVERAGE(OFFSET(B6:INDEX(B6:K6,LARGE(IF(B6:K6<>0,COLUMN(B6:K6)-COLUMN(B6)+1),1)),0,LARGE(IF(B6:K6<>0,COLUMN(B6:K6)-COLUMN(B6)+1),1)-$C$9,1,$C$9))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
How about (with CSE):

=AVERAGE(INDEX(B4:K4,N(IF(1,MATCH(1,0/B4:K4)-{0,1,2,3,4}))))

Regards
 
Upvote 0
Maybe...


B
C
D
E
F
G
H
I
J
K
L
1
2
3
Week 1​
Week 2​
Week 3​
Week 4​
Week 5​
Week 6​
Week 7​
Week 8​
Week 9​
Week 10​
Average​
4
0​
0​
0​
0​
10​
50​
60​
100​
0​
0​
44​
5
0​
0​
0​
5​
10​
50​
60​
100​
0​
0​
45​
6
2​
4​
6​
5​
10​
50​
60​
200​
0​
0​
65​
7
8
9
Weeks Average​
5​

Array formula in L4 copied down
=AVERAGE(OFFSET(INDEX(B4:K4,MATCH(9.99E+307,IF(B4:K4>0,B4:K4,""))),,,,-C$9))
Ctrl+Shift+Enter

M.
 
Upvote 0
To avoid #REF errors, when the relative column of the last number > 0 is less than C9, try this new version


B
C
D
E
F
G
H
I
J
K
L
3
Week 1​
Week 2​
Week 3​
Week 4​
Week 5​
Week 6​
Week 7​
Week 8​
Week 9​
Week 10​
Average​
4
0​
0​
0​
0​
10​
50​
60​
100​
0​
80​
58​
5
0​
0​
0​
5​
10​
50​
60​
100​
0​
0​
45​
6
2​
4​
6​
5​
10​
50​
60​
200​
60​
0​
76​
7
2​
0​
7​
0​
0​
0​
0​
0​
0​
0​
3​
8
9
Weeks Average​
5​

Array formula in L4 copied down
=AVERAGE(OFFSET(INDEX(B4:K4,MATCH(9.99E+307,IF(B4:K4>0,B4:K4,""))),,,,MAX(-MATCH(9.99E+307,IF(B4:K4>0,B4:K4,"")),-C$9)))
Ctrl+Shift+Enter

M.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top