+ Reply to Thread
Results 1 to 11 of 11

Need blank cell to = 0 for AVG function

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    MS 2007
    Posts
    45

    Need blank cell to = 0 for AVG function

    I need to average an array of cells and I need the blank ones to have a value of ZERO in order for my average to be accurate. Right now, blank cells aren't contributing to the average. I don't want to have to populate all the empty cells with a 0 entry.

    E.g. If one cell value is 8 and I need to calculate the avg across 2 cell values, I want the answer to be 4, but it's returning 8 as the average because the 2nd cell is blank.

    In reality, I'm after the average of a larger array of cells, some may be filled and some may be empty, but I need the empty ones to count.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Need blank cell to = 0 for AVG function

    Don't use AVERAGE. SUM the values and divide by the row count. For example,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,731

    Re: Need blank cell to = 0 for AVG function

    You can use this array* formula:

    =AVERAGE(IF(P3:P9="",0,P3:P9))

    *Note that an array formula needs to be committed using the key combination of Ctrl-Shift-Enter (CSE) instead of the usual < Enter >.

    The formula will substitute any blanks in the range P3:P9 with zeros.

    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    07-24-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    MS 2007
    Posts
    45

    Re: Need blank cell to = 0 for AVG function

    That definitely gets me closer and I learned something new, so thank you! But I'm not there yet. Your formula only accounts for number of rows, not number of cells. Let's say I have a value of 8 in a clump of 4 cells (two cells above and two cells below). Your formula gets me an average of 4, but the average should really be 2 across those 4 cells.

  5. #5
    Registered User
    Join Date
    07-24-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    MS 2007
    Posts
    45

    Re: Need blank cell to = 0 for AVG function

    Yay! Pete_UK, that works! Thank you!

    (Referring to =AVERAGE(IF(P3:P9="",0,P3:P9))

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Need blank cell to = 0 for AVG function

    You should get the same result with both formulae.


    A
    B
    C
    1
    2
    8
    1.00
    =SUM(A2:A9)/ROWS(A2:A9)
    3
    1.00
    {=AVERAGE(IF(A2:A9="",0,A2:A9))}
    4
    5
    6
    7
    8
    9

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Need blank cell to = 0 for AVG function

    And, with two above, two below:


    A
    B
    C
    12
    13
    14
    8
    1.60
    =SUM(A12:A16)/ROWS(A12:A16)
    15
    1.60
    {=AVERAGE(IF(A12:A16="",0,A12:A16))}
    16
    17

  8. #8
    Registered User
    Join Date
    07-24-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    MS 2007
    Posts
    45

    Re: Need blank cell to = 0 for AVG function

    Hi TMS, you are right, assuming my array is within a single column. My array is over multiple columns and multiple rows, however.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Need blank cell to = 0 for AVG function

    I don't think that you indicated anywhere in your OP that your array was across multiple columns. No workbook sample, no data and no indicative formula that gives the wrong result.

    Typically, an AVERAGE or AVERAGEIF formula would refer to one column.

    Whatever, a non-array formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-24-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    MS 2007
    Posts
    45

    Re: Need blank cell to = 0 for AVG function

    Thank you, TMS! I like that solution. It's very straightforward.
    And you are right. I should have been more clear in my explanation. I apologize for that. I will get better!

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Need blank cell to = 0 for AVG function

    You're welcome. Thanks for the rep.


    No worries.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] When A Blank Cell Isn't Blank And The List Function
    By Billy Corman in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 12-03-2015, 12:50 PM
  2. Replies: 5
    Last Post: 08-15-2014, 08:33 AM
  3. Replies: 2
    Last Post: 09-10-2012, 04:16 AM
  4. How to Insert Blank row and function into blank cell
    By Mrs_T in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2012, 06:14 PM
  5. Function On/Off Switch for Blank/Non-Blank Cell
    By martinolooney in forum Excel General
    Replies: 2
    Last Post: 11-02-2011, 07:18 AM
  6. Cell is blank but ISBLANK function says its not blank
    By welchs101 in forum Excel General
    Replies: 12
    Last Post: 06-30-2011, 05:31 PM
  7. IF function does not return blank in function cell
    By superdow in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-02-2009, 05:11 PM

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