average without zeros

Fyr

Active Member
Joined
Jan 20, 2009
Messages
375
I'm using this formula:
=AVERAGE(C4,E4,G4,I4,K4,M4)

It a cell contains zero's, it does not average it right.
How can I use the above code to ignore zeros?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
I'm using this formula:
=AVERAGE(C4,E4,G4,I4,K4,M4)

It a cell contains zero's, it does not average it right.
How can I use the above code to ignore zeros?

If the relevant cells are supposed to house numbers >= 0, then:

=SUM(C4,E4,G4,I4,K4,M4)/INDEX(FREQUENCY((C4,E4,G4,I4,K4,M4),{0}),2)
 
Upvote 0
Joined
Jul 30, 2006
Messages
3,656
Fyr,

Aladin's formula is shorter.

But, this also works:
=SUM(SUMIF(INDIRECT({"C4","E4","G4","I4","K4","M4"}),">0"))/INDEX(FREQUENCY((C4,E4,G4,I4,K4,M4),0),2)


Have a great day,
Stan
 
Upvote 0

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,875
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
ADVERTISEMENT
For positive/negative excluding zero/empty/error values, array formula:
{=AVERAGE(IF((MOD(COLUMN(C4:M4)-COLUMN(C4),2)=0)*ISNUMBER(1/C4:M4),C4:M4))}
 
Last edited:
Upvote 0

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,875
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
For positive/negative excluding zero/empty/error values, array formula:
{=AVERAGE(IF((MOD(COLUMN(C4:M4)-COLUMN(C4),2)=0)*ISNUMBER(1/C4:M4),C4:M4))}
The same, but a little bit simpler (array formula):
{=AVERAGE(IF({1,0,1,0,1,0,1,0,1,0,1}*ISNUMBER(1/C4:M4),C4:M4))}
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
For positive/negative excluding zero/empty/error values, array formula:
{=AVERAGE(IF((MOD(COLUMN(C4:M4)-COLUMN(C4),2)=0)*ISNUMBER(1/C4:M4),C4:M4))}

Control+shift+enter:
Code:
=AVERAGE(
  IF(MOD(COLUMN(C4:M4)-COLUMN(C4),2)=0,
  IF(ISNUMBER(C4:M4),
  IF(C4:M4 > 0,
   C4:M4))))

which is an expensive piece formula for a set of 6 cells.

BTW, the matchematicians dislike the idea of exluding 0's if the data set is something like:

3,-3,0,2,1

although either an average of figures > 0 or < 0 is readily accepted.
 
Upvote 0

Forum statistics

Threads
1,195,650
Messages
6,010,915
Members
441,572
Latest member
keobongda8812

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
Top