Average of non-zero values in a dynamic range

VKat13

New Member
Joined
Jan 14, 2014
Messages
19
Hi everyone,

I'm trying to calculate the prior rolling 13 week average (excluding all zero values) and have tried using a nested AVERAGEIFS, OFFSET, INDEX and MATCH formula which seems to work for the below example, but doesn't when I have a non-zero value in Week 4.

My formula is a little convoluted, and my data is as per below.

=AVERAGEIFS(D11:OFFSET(INDEX(D$11:D$28,MATCH(D5,D$11:D$28,0)),16,0),D11:OFFSET(INDEX(D$11:D$28,MATCH(D5,D$11:D$28,0)),16,0),">0",D11:OFFSET(INDEX(D$11:D$28,MATCH(D5,D$11:D$28,0)),16,0),"<>"&D5)

I'm pretty sure I need to use an INDIRECT function instead given that my range will continuously change, but I'm not sure how to write it.

Apologies if I don't make sense. I've been racking my brain for the last few hours trying to get this to work.

Thanks in advance for your help!
Week #Bananas
Week 10
Week 236,090
Week 30
Week 40
Week 50
Week 630,261
Week 721,505
Week 826,489
Week 920,909
Week 1023,863
Week 1123,491
Week 1221,994
Week 1322,687
Week 1423,961
Week 1522,624
Week 1622,785
Week 1730,823
Week 1830,324

<TBODY>
</TBODY><COLGROUP><COL><COL></COLGROUP>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The figure in week 13 is the first non-zero value from where I want the 13 week rolling average to start the calculation.
The figure 36,090 is the current week which should be excluded in the average as I would like to calculate the current week vs. the 13 wk average later on.
 
Upvote 0
The figure in week 13 is the first non-zero value from where I want the 13 week rolling average to start the calculation.
The figure 36,090 is the current week which should be excluded in the average as I would like to calculate the current week vs. the 13 wk average later on.

B6, just enter:
Rich (BB code):
=MATCH(B4,A:A,0)+1
where B4 houses the week value corresponding to the first >0 value.

For average of the next 13 >0 values:

Control+shift+enter, not just enter:
Rich (BB code):
=AVERAGE(IF(ROW(INDEX(B:B,B6):B25)<=
  SMALL(IF(ISNUMBER(1/INDEX(B:B,B6):B25),
  ROW(INDEX(B:B,B6):B25)),MIN(COUNT(INDEX(B:B,B6):B25),13)),
  IF(ISNUMBER(1/INDEX(B:B,B6):B25),INDEX(B:B,B6):B25)))
 
Upvote 0
GENIUS!! Works perfectly!
Very, very much appreciate the time you took to help and if I could give you hug I would!!
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,770
Members
449,095
Latest member
m_smith_solihull

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