Averaging noncontiguous numbers ignoring zeros?

G

Guest

Averaging noncontiguous numbers ignoring zeros?

I'm trying to calculate an average but I want to not include any values of
zero. I've seen examples here and in Microsft help for contiguous values (ex:
A1:A7) but not for the averages of noncontiguous data (ex: A1, A3, A5).

I found Microsoft's example using contiguous data under "Calculate the
average of numbers, ignoring zero (0) values". They show how to average
A1:A6 using:
=AVERAGE(IF(A2:A7<>0, A2:A7,"")) . I've not been able to revise this
formula to calculate noncontiguous data. Any ideas?
 
B

Biff

Hi!

Is there a specific pattern like your example of A1, A3,
A5 or are the cells scattered all over the place?

Biff
 
A

Andy Brown

Mike said:
Averaging noncontiguous numbers ignoring zeros?
=AVERAGE(IF(A2:A7<>0, A2:A7,"")) . I've not been able to revise this
formula to calculate noncontiguous data. Any ideas?

=SUM(A2:A7)/COUNTIF(A2:A7,">0")

, possibly.

HTH,
Andy
 
G

Guest

There is a specific pattern. All the cells are in the same row with two
columns of data after each cell.
 
M

Myrna Larson

But A2:A7 is not a group of non-contiguous cells. I think the example he gave
was A1, A3, A5

That can be solved with an array formula that involves MOD and the the row
number, but if he wants something like A2:A7, B9:B13, C1:C3, etc., that won't
work, either.

Another possibility is to select the various cells and assign a name to them.
Then a simple =AVERAGE(MyRange) will do.
 
A

Andy Brown

Myrna Larson said:
But A2:A7 is not a group of non-contiguous cells. I think the example he gave
was A1, A3, A5

Of course, but A2:A7 can *contain* a group of non-contiguous cells.
 
G

Guest

Myrna,
Thanks, but not sure if I follow your idea. I "simply" want to average only
those cells in A1, A3, and A5 that have a value <>0 . Not sure how MOD would
work in this case.
 
G

Guest

OK, I figured it out. Here's my solution:
=(C26+G26+K26)/(3-(COUNTIF(K26,0)+(COUNTIF(G26,0))+(COUNTIF(C26,0))))

Still open for any other approaches that work.
 
D

Dave R.

Here is an array example of how MOD could come into play;

=AVERAGE(IF((MOD(COLUMN(A1:p1)-1,3)=0)*(A1:p1<>0),A1:p1))

with your values in A1:p1, averaging every 3rd column if <> 0.
 
M

Myrna Larson

Huh? Do you mean that all of the cells in A2:A7 aren't filled, i.e. the DATA
isn't contiguous (certainly those CELLS are contiguous).

Let's say there is data in ALL of those cells, but he only wants to average
A3, A4, A5, and A6. I don't see how your formula will average just those
cells.
 
M

Myrna Larson

MOD would work in the case of A1, A3, and A5, where you want every-other
column. The array formula would be

=AVERAGE(IF(MOD(ROW(A1:A5),2)=1,IF(A1:A5<>0,A1:A5)))

But that will not work for the example/solution you posted most recently,
which refers to cells C26, G26, and K26. The column numbers are 3, 7, and 11,
so there's no numeric relationship between them.

OTOH, if you wanted C26, G26, and *J26*, you could use

MOD(COLUMN(C26:J26),4)=3

because that's every 4th column.
 
A

Andy Brown

Myrna Larson said:
Huh? Do you mean that all of the cells in A2:A7 aren't filled

That's the inference of the original question, AFAI can tell. A2:A7 *can*
contain a group of non-contiguous cells, eg: A3, A5, A7.
 
M

Myrna Larson

PS: If you need this formula just once on the worksheet, you could assign a
name to cells C26, G26, and K26. But if you have to do that for every row,
that may not be feasible.
 
A

Andy Brown

Myrna Larson said:
MOD would work in the case of A1, A3, and A5, where you want every-other
column. The array formula would be

=AVERAGE(IF(MOD(ROW(A1:A5),2)=1,IF(A1:A5<>0,A1:A5)))

But that will not work for the example/solution you posted most recently,
which refers to cells C26, G26, and K26. The column numbers are 3, 7, and 11,
so there's no numeric relationship between them.

Actually, the relationship is +1 = 4*1, 4*2, 4*3.

Rgds,
Andy
 
H

Harlan Grove

Mike wrote...
Unfortunately the data is not in a range so I can't use any A2:A7
functions.

If the data is stored in worksheet cells, then it's stored in ranges,
though likely not single area ranges.

There is a way to do this for a general, multiple area range X. It
requires using a defined name like seq referring to

=ROW(INDIRECT("1:1024"))

and it's a HUGE array formula. Like this,

=SUM(SUMIF(INDIRECT(MID(CELL("Address",(IV65536,X)),
SMALL(IF(MID(","&CELL("Address",(IV65536,X)),seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1)))),
SMALL(IF(MID(CELL("Address",(IV65536,X))&",",seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1))))
-SMALL(IF(MID(","&CELL("Address",(IV65536,X)),seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1)))))),">0"))
/SUM(COUNTIF(INDIRECT(MID(CELL("Address",(IV65536,X)),
SMALL(IF(MID(","&CELL("Address",(IV65536,X)),seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1)))),
SMALL(IF(MID(CELL("Address",(IV65536,X))&",",seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1))))
-SMALL(IF(MID(","&CELL("Address",(IV65536,X)),seq,1)=",",seq),
ROW(INDIRECT("1:"&(AREAS(X)+1)))))),">0"))

This assumes cell IV65536 is blank.
 
A

Andy Brown

Harlan Grove said:
If the data is stored in worksheet cells, then it's stored in ranges,

Finally!!! ; it takes a genius to understand an idiot -- the latter being
me, BTW, not Mike.
 
M

Myrna Larson

Good catch, but I think you mean -1, i.e. the column numbers to be added are:
COLUMN() = 4*i-1, where i = an integer. Solving for i, the formula would be

=(COLUMN()+1)/4)=INT(COLUMN()+1/4)
 
M

Myrna Larson

I counted wrong: column K is 11, J is 10, so

MOD(COLUMN(C26:K26),4)=3

would average C26, G26, and K26 (not J26)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top