Share via

how to average, ignoring zero

Anonymous
2011-09-15T18:39:31+00:00

Okay, so my boss wants me to average 4 months worth of percentages for our contractors.  But some contractors have 0% in some months and my boss doesn't want those counted (the contractor may not be assigned yet).

Is there a way to do this?

Thanks.

Heather

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

8 answers

Sort by: Most helpful
  1. Anonymous
    2011-09-16T02:28:45+00:00

    Hi,

    Let's say that the range is A1:A10

    (change as yours)

    step1

    in cell A11 write:

    =myaverage(A1:A10)

    step2

    ALT+F11 to open VB editor.

    Insert > module and paste the code below on the right

    Close VB editor.

    .........................

    Function myaverage(rng As Range)

    t = 0

    s = 0

    For Each r In rng

    If r.Value > 0 Then

    t = t + 1

    s = s + r.Value

    End If

    Next r

    myaverage = Round(s / t, 2)' 2 decimal places, change as yours

    End Function

    cell A11 Format Percentage

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-09-15T20:12:45+00:00

    I tried that, substituting the A's for the correct letters and got a #VALUE error.

    My apologies. I should have noted that you were on Office XP (aka 2002) but didn't. You cannot use the full column references. Substitute with something like,

    =AVERAGE(IF(A1:A999>0,A1:A999))

    ... or,

    =AVERAGE(IF(A1:A999<>0,A1:A999))

    ... and enter with Ctrl+Shift+Enter.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-09-15T19:50:33+00:00

    I'll approach from a different angle.  Assume your numbers (and zeros, etc) are in column A, beginning at row 2 and ending at row 1052

    =SUMIF(A2:A1052,">0") / COUNTIF(A2:A1052,">0")

    That would calculate average of all POSITIVE, non zero values.  If you literally need average of non-zero values, positive and negative, then:

    =SUMIF(A2:A1052,"<>0") / COUNTIF(A2:A1052,"<>0")

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-09-15T19:24:41+00:00

    I tried that, substituting the A's for the correct letters and got a #VALUE error.

    Can you tell me what the exact formula would be?

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2011-09-15T18:48:50+00:00

    If the numbers to be averaged are in column A, try this array formula,

    =AVERAGE(IF(A:A>0,A:A))

    ... for greater-than-zero values or,

    =AVERAGE(IF(A:A<>0,A:A))

    ... if all non-zero values are to be considered (including less-than-zero)

    Note that those formulas are array formulas and need to be entered with Ctrl+Shift+Enter↵ rather than simply Enter↵. If done correctly, Excel will wrap the formula in braces like this,

    { =AVERAGE(IF(A:A<>0,A:A)) }

    Was this answer helpful?

    0 comments No comments