Sum cells unless a cell = 0

RodneyC

Active Member
Joined
Nov 4, 2021
Messages
278
Office Version
  1. 2016
Platform
  1. Windows
I'm using this formula

=SUM($E4:$Q4)/12

to sum the values in a row. For some of the rows, some of the values in E:Q are 0. If that is the case, I want the value 12 to change to however many values E:Q are greater than 0. Example, if only 8 of the values E:Q were greater than 0 then the formula would change the 12 to an 8.

Make sense?

Thanks in advance
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
=SUM(E4:Q4)/COUNT(E4:Q4)

or just

=AVERAGE(E4:Q4)

Also, E:Q is 13 columns. Not sure that makes a difference.
 
Upvote 0
how about

=SUM($E4:$Q4)/COUNTIF($E4:$Q4,">"&0)
 
Upvote 0
I'm using this formula

=SUM($E4:$Q4)/12

to sum the values in a row. For some of the rows, some of the values in E:Q are 0. If that is the case, I want the value 12 to change to however many values E:Q are greater than 0. Example, if only 8 of the values E:Q were greater than 0 then the formula would change the 12 to an 8.

Make sense?

Thanks in advance
This can be too...
=SUM(E4:Q4)/COUNTIFS($E$4:$Q$4,"<>0")
 
Upvote 0
Also bear in find that if you do not have any values in columns E:Q, you will get a #DIV/0 error message.

You can fix that by wrapping whatever formula you choose to use in an IFERROR function, i.e.
=IFERROR(your formula,"")
 
Upvote 0
thanks everyone, I went with this becauase it was the first one I saw: =SUM($E4:$Q4)/COUNTIF($E4:$Q4,">"&0)
 
Upvote 0
What about the single function designed exactly for that sort of thing?
Excel Formula:
=AVERAGEIF($E4:$Q4,">0")
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,946
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top