MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2003, 12:40 AM   #1
Bytes37
 
Join Date: Mar 2003
Posts: 20
Default Averages..problem with 0s...can you please help!

I have a column with values in it. Some are 0s and some values are not. If I average the column, it gives me the average of all the values including the 0s. How do I make excel not count the 0s in computing an average?

Thanks!
Bytes37 is offline   Reply With Quote
Old Mar 26th, 2003, 12:51 AM   #2
brucesw
 
Join Date: Nov 2002
Location: Brisneyland, Australia
Posts: 271
Default

It may not be simple, but...
Add a column with the formula;
=IF(datacell=0,"nil","excludes nil") Call the column "Flag"
Create a pivot table and drag your data into the data part of the wizard. Drag the new column "Flag" to the page part of the wizard, select finish.

If you select "excludes nil" from the dropdown next to "Flag" you'll get your answer.

Good luck
brucesw is offline   Reply With Quote
Old Mar 26th, 2003, 12:52 AM   #3
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

If you only have positve numbers, you could use
=SUM(A1:A10)/COUNTIF(A1:A10,">0")

otherwise array enter (control shift enter)
=AVERAGE(IF(A1:A4,A1:A4))

good luck
IML is offline   Reply With Quote
Old Mar 26th, 2003, 12:52 AM   #4
Jaafar Tribak
 
Jaafar Tribak's Avatar
 
Join Date: Dec 2002
Location: Larache--Morocco
Posts: 2,473
Default

Hi,

Assuming the range of wich you want to compute the average is A1:A10,
you can try this Array Formula:

{=SUM(IF(NOT(A1:A10),0,A1:A10))/COUNTIF(A1:A10,"<>0")}

Hope this helps.
__________________
Jaafar.

Happiness is when what you think, what you say, and what you do are in harmony.




http://www.laracheenelmundo.com/
Jaafar Tribak is offline   Reply With Quote
Old Mar 26th, 2003, 01:53 AM   #5
2rrs
 
Join Date: Dec 2002
Posts: 346
Default

Hi,
You can also use these;

Average contiguous cells containing zeros

SUM(range)/MAX(1,COUNT(range)-COUNTIF(range,0))

Average noncontiguous cells containing zeros

SUM(range)/COUNTIF(range,">"&0)

Hope this helps, 2rrs
2rrs is offline   Reply With Quote
Old Mar 26th, 2003, 02:09 AM   #6
NateO
MrExcel MVP
Admin
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,228
Default

Howdy,

Quote:
Originally Posted by 2rrs
Average noncontiguous cells containing zeros
SUM(range)/COUNTIF(range,">"&0)
I don't think you can use countif on a noncontiguous range. But you can use something like this.
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
NateO is offline   Reply With Quote
Old Mar 26th, 2003, 02:16 AM   #7
PaddyD
MrExcel MVP
 
Join Date: May 2002
Posts: 12,352
Default

Hi Nate

Takes a bit of work, but you can use countif on non-contiguous ranges:

http://www.mrexcel.com/board2/viewto...=136110#136110

whether you'd want to is another matter!

paddy
PaddyD is offline   Reply With Quote
Old Mar 26th, 2003, 02:20 AM   #8
NateO
MrExcel MVP
Admin
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,228
Default

Right Paddy, nice catch. Actually I had seen this here. I should have said, like as quoted... But yes, nice link Paddy, and I should consider my words a little more wisely...
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
NateO is offline   Reply With Quote
Old Mar 26th, 2003, 04:37 PM   #9
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

Just for variety, the following non-array could also be used for positive and negative in a contiiguous range:
=SUM(A1:A10)/MAX(1,SUM(COUNTIF(A1:A10,{">0","<0"})))
IML is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT +1. The time now is 07:23 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.