+ Reply to Thread
Results 1 to 38 of 38

averaging selected cells excluding zero

  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    averaging selected cells excluding zero

    Could someone please help me with my problem. I wanted to average selected cells excluding the value zero. Also, I wanted to make the value of cell is zero and not to display the error #DIV/0! if the denominator is zero.

    A1 = Denominator

    Selected cell:
    A3, A5, A6, A8

    Would really appreciate you're prompt reply and assistance. thanks

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Try...

    =IF(A1,SUM(A3,A5,A6,A8)/A1,0)

  3. #3
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: averaging selected cells excluding zero

    Get it please

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

    Comitted w/ CTRL+SHIFT+ENTER
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    Try...

    =IF(A1,SUM(A3,A5,A6,A8)/A1,0)
    Thank you very much for your prompt response. I was looking to my excel sheet and I didn't notice that the denominator should be the number of cells selected excluding zero and not to display the error if the denominator is zero.

    Ex.

    A1=0
    A2=3
    A3=2

    the denominator should be only 2 since A1 is zero.

  5. #5
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Are the relevant cells located in a contiguous range of cells, as in your last example? Or are they located in a non-contiguous range of cells, as in your original post?

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: averaging selected cells excluding zero

    =sum(a3,a5,a6,a8)/sum(if(a3,1,0)+if(a5,1,0)+if(a6,1,0)+if(a8,1,0))
    which is
    =SUM(A3,A5,A6,A8)/SUM(IF(A3,1,0),IF(A5,1,0),IF(A6,1,0),IF(A8,1,0))
    Last edited by martindwilson; 05-13-2009 at 03:41 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    Are the relevant cells located in a contiguous range of cells, as in your last example? Or are they located in a non-contiguous range of cells, as in your original post?
    Its the former. As in my original post. thanks

  8. #8
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by martindwilson View Post
    =sum(a3,a5,a6,a8)/sum(if(a3,1,0)+if(a5,1,0)+if(a6,1,0)+if(a8,1,0))
    which is
    =SUM(A3,A5,A6,A8)/SUM(IF(A3,1,0),IF(A5,1,0),IF(A6,1,0),IF(A8,1,0))
    Wow this is the exact formula I needed thanks for your help

  9. #9
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Assuming that the data does not contain negative numbers, here's another way...

    =SUM(A1,A3,A5,A6,A8)/INDEX(FREQUENCY((A1,A3,A5,A6,A8),0),2)

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: averaging selected cells excluding zero

    you could also use (its 4 characters shorter lol
    =SUM(A3,A5,A6,A8)/SUM(--(A3<>0),--(A5<>0),--(A6<>0),--(A8<>0))

  11. #11
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by martindwilson View Post
    =sum(a3,a5,a6,a8)/sum(if(a3,1,0)+if(a5,1,0)+if(a6,1,0)+if(a8,1,0))
    which is
    =SUM(A3,A5,A6,A8)/SUM(IF(A3,1,0),IF(A5,1,0),IF(A6,1,0),IF(A8,1,0))
    Hi, thank you for your response this is the exact formula I needed. But, I also wanted to make the value of cell to display 0 if the value of the denominator is 0 and to eliminate the error #DIV/0!. I wanted this because I'm going to change the datas every month and I don't want to change the formula if all the values in the cells are 0. thanks

  12. #12
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: averaging selected cells excluding zero

    how about

    =SUMPRODUCT(SUM(C2:H2),(1/SUM(--(C2:H2>0))))
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  13. #13
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: averaging selected cells excluding zero

    I think this takes care of your 0 problem!

    =SUMPRODUCT(SUM(C2:H2),1/(SUM(--(C2:H2>0))+(SUM(--(C2:H2>0))=0)))

  14. #14
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by squiggler47 View Post
    I think this takes care of your 0 problem!

    =SUMPRODUCT(SUM(C2:H2),1/(SUM(--(C2:H2>0))+(SUM(--(C2:H2>0))=0)))

    Hi thanks but the problem is the cells are in a non-contiguous range.

    ex.

    A1
    A4
    A6

  15. #15
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    here's the formula I used:

    =SUM(W12,W17,W22,W27)/SUM(IF(W12,1,0)+IF(W17,1,0)+IF(W22,1,0)+IF(W27,1,0))

    I wanted to eliminate the error #DIV/0! if the the cells are 0.

  16. #16
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: averaging selected cells excluding zero

    sorry i should have read all the post

    =SUM(w12,w17,w22,w27)/(SUM(w12>0,w17>0,w22>0,w27>0)+(SUM(w12>0,w17>0,w22>0,w27>0)=0))

    only saw the contiguous range

  17. #17
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Try...

    =SUM(W12,W17,W22,W27)/MAX(1,(W12<>0)+(W17<>0)+(W22<>0)+(W27<>0))

  18. #18
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,004

    Re: averaging selected cells excluding zero

    Perhaps,

    Please Login or Register  to view this content.
    Last edited by windknife; 05-14-2009 at 12:47 PM.

  19. #19
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    Try...

    =SUM(W12,W17,W22,W27)/MAX(1,(W12<>0)+(W17<>0)+(W22<>0)+(W27<>0))
    Thank you for this really appreciated.

    So I've been working a report for almost a week now. Am kinda novice in using excel. And I still see some flaws to my computation. I hope somebody would help me with this.

    Kindly refer to the attached file.

    For B13, I wanted to average C13:G13 but to exclude the 0% from averaging if C13,D13,E14,F14,G14 = 0

    ex. For D13, it is included in averaging since the value of D11 is 1
    For E14, it is not included in the average since the the value of E11 is 0 so on and so forth..
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    04-21-2009
    Location
    Nottingham
    MS-Off Ver
    Excel 2003
    Posts
    66

    Re: averaging selected cells excluding zero

    You could work the average by excluding cells that are zero by summing the column, and then dividing by ceels different to 0.

    The fomula would mean you would do a =SUM(A1:A20)/COUNTIF(A1:A20,"<>0") - for example

  21. #21
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: averaging selected cells excluding zero

    kevint it's non contiguous cells thats required,else everyone would have posted same solution!!!!!!!!!!!!!!!!!!!!!!!!!!

  22. #22
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by bambino86 View Post
    Thank you for this really appreciated.

    So I've been working a report for almost a week now. Am kinda novice in using excel. And I still see some flaws to my computation. I hope somebody would help me with this.

    Kindly refer to the attached file.

    For B13, I wanted to average C13:G13 but to exclude the 0% from averaging if C13,D13,E14,F14,G14 = 0

    ex. For D13, it is included in averaging since the value of D11 is 1
    For E14, it is not included in the average since the the value of E11 is 0 so on and so forth..

    hope someone could help me with my problem.

  23. #23
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Somewhat unclear... Can you try to re-post your question, provide a representative sample of the data, and provide the actual result you expect.

  24. #24
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Smile Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    Somewhat unclear... Can you try to re-post your question, provide a representative sample of the data, and provide the actual result you expect.
    Hi Domenic,

    Sorry for being unclear. I'll try to explain my problem as much as I can.
    Kindly refer to the attached sample sheet (post #19). I wanted to put a formula for B18. I want to get the average C18, D18, E18, F18, and G18. But the problem is I wanted to exclude a cell or cells in averaging if the value of cells C11, D11, E11, F11, and G11 is equal to 0%. For ex. the value of D18 is 0% but the value of of D11 is 1. Thus, it will be included in averaging. As for E18, F18 and G18, it will be not be included since their cell counterparts have the value of 0%. So the inclusion of cells C18 to G18 will depend to the value of C11 to G11.

    Can you make a formula for both non contiguous and contiguous cells. thank you very much for your assistance.
    Last edited by bambino86; 05-16-2009 at 04:21 PM. Reason: refer to post #19 for the attached sample sheet

  25. #25
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: averaging selected cells excluding zero

    No attachment.
    Entia non sunt multiplicanda sine necessitate

  26. #26
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    For contiguous cells, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

    Please Login or Register  to view this content.
    With regards to non-contiguous cells, where are the relevant cells located?
    Last edited by Domenic; 05-16-2009 at 04:29 PM.

  27. #27
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    For contiguous cells, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

    Please Login or Register  to view this content.
    With regards to non-contiguous cells, where are the relevant cells located?
    Thanks Domenic. For non-contiguous cells C18, E18, and G18.

  28. #28
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    For non-contiguous cells, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

    Please Login or Register  to view this content.
    For a large range, where the pattern is consistent (every 2nd cell), try the following formula (adjust the range accordingly)...

    Please Login or Register  to view this content.
    ...confirmed with CONTROL+SHIFT+ENTER
    Last edited by Domenic; 05-16-2009 at 05:30 PM.

  29. #29
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Smile Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    For non-contiguous cells, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

    Please Login or Register  to view this content.
    For a large range, where the pattern is consistent (every 2nd cell), try the following formula (adjust the range accordingly)...

    Please Login or Register  to view this content.
    ...confirmed with CONTROL+SHIFT+ENTER
    Wow you really lived up to your title "Forum Guro" very informative and helpful. Thank you for your help

  30. #30
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    For non-contiguous cells, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

    Please Login or Register  to view this content.
    For a large range, where the pattern is consistent (every 2nd cell), try the following formula (adjust the range accordingly)...

    Please Login or Register  to view this content.
    ...confirmed with CONTROL+SHIFT+ENTER
    Hi Domenic,

    I'm sorry to trouble you again. I tried the formula and it works for excel 2007. But when I tried it in Excel 2003 the formula is not committing (CONTROL+SHIFT+ENTER is not working, the braces disappears) I don't know what am I doing wrong. Please help

  31. #31
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    When you confirmed with CONTROL+SHIFT+ENTER, did you first press down both the CONTROL and SHIFT keys, then while both keys were pressed down, press the ENTER key? Note that if you're using a Mac version of Excel (although I doubt it -- Excel 2003 is windows based), you'll need to confirm with COMMAND+RETURN instead. Have a look at the attached sample file.
    Attached Files Attached Files

  32. #32
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    When you confirmed with CONTROL+SHIFT+ENTER, did you first press down both the CONTROL and SHIFT keys, then while both keys were pressed down, press the ENTER key? Note that if you're using a Mac version of Excel (although I doubt it -- Excel 2003 is windows based), you'll need to confirm with COMMAND+RETURN instead. Have a look at the attached sample file.
    Yes I first pressed down Control and Shift keys first and then hit enter. I opened your file and when I'm double clicking cell A2 and A4 the braces dissappear. is there something wrong with the excel version that i'm using?

  33. #33
    Registered User
    Join Date
    05-17-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: averaging selected cells excluding zero

    Hi,

    I am new to this forum pls help me out in posting the quiery..

    Cheers,
    PRIYA

  34. #34
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Quote Originally Posted by bambino86 View Post
    Yes I first pressed down Control and Shift keys first and then hit enter. I opened your file and when I'm double clicking cell A2 and A4 the braces dissappear. is there something wrong with the excel version that i'm using?
    I'm going offline now... but if you're double clicking A2 and A4, you'll need to re-confirm each one with CONTROL+SHIFT+ENTER.

  35. #35
    Registered User
    Join Date
    05-17-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: averaging selected cells excluding zero

    Hi,

    Pls help me in solving the excel where in i an preparing an Histroy detail for the training.

    Hence i have doubt in solving which i have hightlighted in the red colour.

    Pls help me out in solving it..

    Cheers,
    PRIYA
    Attached Files Attached Files

  36. #36
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: averaging selected cells excluding zero

    Please take a few minutes to read the forum rules, and then start your own thread.

  37. #37
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Manila philippines
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: averaging selected cells excluding zero

    Quote Originally Posted by Domenic View Post
    I'm going offline now... but if you're double clicking A2 and A4, you'll need to re-confirm each one with CONTROL+SHIFT+ENTER.
    Hi Domenic,

    Thanks for assistance. I have already resolved the problem with confirming the formula. I restarted my pc and and at last it did work. However, I noticed that the formula you provided to me still doesn't resolved the error DIV#0 if all the value is 0. Could I trouble you again to amend if possible the formula to resolve the error? I'm really desperate to solve the issue as I'm going to present a report using this formula to my big bosses. thank you

    =AVERAGE(IF(C11:G11<>0,C13:G13))

  38. #38
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: averaging selected cells excluding zero

    Try...

    =LOOKUP(9.99999999999999E+307,CHOOSE({1,2},0,AVERAGE(IF(C11:G11<>0,C13:G13))))

    ...confirmed with CONTROL+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