Equation to retrieve the average of the last three non-zero entries in a range

SloFlyer

New Member
Joined
Feb 1, 2005
Messages
16
I would like to get an cell equation that provides the average of the last three non-zero entries in a range. Given the data
Value Desired Result
1
0
0
2
3 2
0 2
4 3
0 3
5 4
6 5
7 6
8 7
0 7
9 8
0 8

where cell A1="Value" and "A15"=9 etc. Starting with row 6, the average of the last three non-zero entries in column A is 2=(1+2+3)/3 in cell "B6" for the range "A2:A6". In cell "B14", the average is 7=(6+7+8)/3 for the range "A2:A14". I tried to come up with a range that would grow or shrink to get three non-zero cells, but couldn't work it out. HELP!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this array formula in B6

=AVERAGE(IF(A$2:A6<>0,IF(ROW(A$2:A6)>=LARGE(IF(A$2:A6<>0,ROW(A$2:A6)),3),A$2:A6)))

confirm with CTRL+SHIFT+ENTER and copy down
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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