+ Reply to Thread
Results 1 to 4 of 4

Averages excluding zeros

  1. #1
    Jaytee
    Guest

    Averages excluding zeros

    Is there a way to average a column of numbers, but have Excel ignore "0"s?
    For example if my column is:
    2
    3
    4
    0
    1
    0
    Excel will average this as 1.67 (sum of 10 divided by 6 entries) , but what
    I need is 2.5 ( Sumof 10 divided by 4 non-zero entries.)
    Bonus Question: Is there a way to create this effect in a Pivot Table?

  2. #2
    vezerid
    Guest

    Re: Averages excluding zeros

    Jaytee,

    Assuming your data are in A1:A6,

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

    This is an *array* formula, hence it should be committed with
    Shift+Ctrl+Enter

    HTH
    Kostis Vezerides


  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    I suggest using the following user defined function

    Function AverageWithOutZeros(DataRange As Range)
    For Each Cell In DataRange
    If Cell <> 0 Then
    Total = Total + Cell
    Count = Count + 1
    End If
    Next Cell
    If Count <> 0 Then
    AverageWithOutZeros = Total / Count
    Else
    AverageWithOutZeros = "#N/A"
    End If
    End Function

    Paste this into a macro sheet and it should then be available on the insert function menu item.
    Martin

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,702
    If you don't have negative values

    =SUM(A1:A10)/MAX(1,COUNTIF(A1:A10,">0"))

    or

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

    confirmed with CTRL+SHIFT+ENTER

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1