ignoring zero values in calculations

Kourada

New Member
Joined
Apr 8, 2002
Messages
17
I cells A1:A3 I have the numbers 5,0,5 respectivly. In Cell A4, I have the formula Average(A1:A3). I want the zero value to be ignored in the calculation, so that the result of the average is "5". Data is continuously added to the spreadsheet, and I never know which of the cells will have a zero value, so just averaging cells A1 and A3 is not an option.

Any ideas?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
On 2002-05-12 13:16, Kourada wrote:
I cells A1:A3 I have the numbers 5,0,5 respectivly. In Cell A4, I have the formula Average(A1:A3). I want the zero value to be ignored in the calculation, so that the result of the average is "5". Data is continuously added to the spreadsheet, and I never know which of the cells will have a zero value, so just averaging cells A1 and A3 is not an option.

Any ideas?

{=AVERAGE(IF(A1:A3,A1:A3))}

Note: This is an array formula which must be entered using the Control+Shift+Enter key combination.
 
Upvote 0
Thanks, that works perfectly.....but why? I don't get it. Why was the zero ignored using that array formula?
 
Upvote 0
Array enter (Ctrl-Shift-Enter)one of the following:

=IF(COUNTIF(A1:C1,">0"),AVERAGE(IF(A1:C1=0,"",A1:C1)),"")

=IF(COUNTIF(A1:C1,">0")=0,"",AVERAGE(IF(A1:C1=0,"",A1:C1)))

=AVERAGE(IF(A1:C1,A1:C1)) gives error if all numbers are 0.
 
Upvote 0
On 2002-05-12 13:30, Kourada wrote:
Thanks, that works perfectly.....but why? I don't get it. Why was the zero ignored using that array formula?

When A1:A3 contains {5;0;5} the array formula, {=IF(A1:A3,A1:A3)}, produces {5;FALSE;5} because IF treats all non-zero values as TRUE and zero values as FALSE. The array formula, {=IF(A1:A3,A1:A3)}, returns the numbers (in A1:A3) themselves when TRUE and the boolean value, FALSE, when 0. The AVERAGE function ignores boolean (logical) values. So =AVERAGE({5;FALSE;5}) produces 5.
This message was edited by Mark W. on 2002-05-12 15:05
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,011
Members
448,935
Latest member
ijat

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