On 2002-03-01 21:05, Dreamboat wrote:
I bow to MrExcel MVP, but would like to ask:
Why do you need the *max* part?
This worked for me:
=SUMIF(A1:A4,">0")/COUNTIF(A1:A4,">0")
Consider
{0.00,0.00,"",0.00}
in A1:A4.
Applied to the above set of values
[1]
=SUMIF(A1:A4,">0")/COUNTIF(A1:A4,">0")
will result in #DIV/0!, while
[2]
=SUM(A1:A4)/MAX(1,COUNTIF(A1:A4,">0"))
will compute 0.
The formula in [2] assumes the benign condition that the range of interest does not house negative numbers. To average positive non-zero values, it needs to be rewritten as:
[3]
=SUMIF(A1:A4,">0")/MAX(1,COUNTIF(A1:A4,">0"))
In order to average both neg and pos values excluding zeroes, [2] must be expanded to:
[4]
=SUM(A1:A4)/MAX(1,COUNTIF(A1:A4,">0")+COUNTIF(A1:A4,"<0"))
which is exactly eq to the array-formula
[5]
{=AVERAGE(IF(A1:A4,A1:A4))}
By the way, the formula in [5] cannot cope (without modification) with the formula returned blanks in the range of interest, while [4] would.
Aladin