How to Average the last 8 GOOD data entries, without VBA, OFFSET, or Array Function?

wiseone

Board Regular
Joined
Mar 14, 2015
Messages
144
Hi All,

Trying to keep my 10MB spreadsheet fast.

I have 52 weeks of data which changes weekly and I need to average the last 8 weeks of good data, preferably without OFFSET (but if I have to I have to), an Array function, or VB.

Good Data: Not=<0, not>=1, not text, not blank.

Or you could say: Good data is between 0 and 1. (For some reason the greater than and less than symbol kept disappearing when I posted this thread).
<gooddata<1<good data<1.

Example:

Week3637383940414243444546474849505152
Data.2 1.781.5211.1.2.15.80.71.99.58

<tbody>
</tbody>

Would return the average of the last 8 good data cells (green text) = 0.505

Thanks in advance!</gooddata<1<good>
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Admiral100's solution (the very first reply) handles text entries and inserting/deleting rows/columns
 
Last edited:
Upvote 0
Code:
=sumproduct(lookup(large(($b2:$r2>0)*($b2:$r2<1)*column($b2:$r2),row(indirect("1:8",1))),column($b2:$r2),$b2:$r2))/min(8,sumproduct(($b2:$r2>0)*($b2:$r2<1)))
 
Upvote 0
No, if any rows gets inserted anywhere between row 1 and row 8 they would cause issues. Much easier to just use ROW(INDIRECT("1:8",1))

You could use {1;2;3;4;5;6;7;8} instead, but of course that doesn't scale as well.
 
Upvote 0
Code:
=sumproduct(lookup(large(($b2:$r2>0)*($b2:$r2<1)*column($b2:$r2),row(indirect("1:8",1))),column($b2:$r2),$b2:$r2))/min(8,sumproduct(($b2:$r2>0)*($b2:$r2<1)))

Is there a way to mod this to work so if there is less than 8 weeks good data it still averages?
 
Upvote 0
No, if any rows gets inserted anywhere between row 1 and row 8 they would cause issues. Much easier to just use ROW(INDIRECT("1:8",1))

If one is going for speed, one should avoid INDIRECT, and other volatile functions like the plague.
 
Upvote 0
@stunnrock, the denominator of your formula handles less than 8, but not the numerator. Specifically, the LARGE function will start throwing errors if there are less than 8 valid numbers. We can adapt your formula by including IFERROR like so:

=SUM(IFERROR(LOOKUP(LARGE(($B2:$R2>0)*($B2:$R2<1)*COLUMN($B2:$R2),{1;2;3;4;5;6;7;8}),COLUMN($B2:$R2),$B2:$R2),0))/MIN(8,SUMPRODUCT(($B2:$R2>0)*($B2:$R2<1)))
and confirm with Control+Shift+Enter.

@wiseone, yes this is an array formula, but it really doesn't take significantly longer than stunnrock's previous version. It does the exact same processing as the previous version, just including IFERROR, which is a fast function (according to Microsoft).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,637
Members
449,461
Latest member
kokoanutt

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