Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Averaging a Non-Contiguous Range.

Averaging a Non-Contiguous Range

by Allen Wyatt
(last updated July 31, 2017)

24

Tom needs to average a series of non-contiguous cells, excluding any cells that may contain zero values. Specifically, he needs to average cells A1, C1, E1, G1, and J1, but only counting those cells that don't contain zero.

Before getting into what works, let's take a look at what doesn't work. First of all, it doesn't work to simply add the cells and divide by 5; that doesn't take zero values into account. Second, it doesn't work to use COUNTIF in the denominator of your formula, as shown here:

=(A1+C1+E1+G1+J1) / COUNTIF(A1:J1,"<>0")

This doesn't work because it examines and counts cells within the entire range of A1:J1, not just the five cells you want considered in the average. You might also think that you could select your five non-contiguous cells, give them a name, and then use the name in your formula. While Excel allows you to create the name, the following gives an error:

=SUM(MyCells) / COUNTIF(MyCells,"<>0")

It appears that COUNTIF will only work with a single contiguous range, so the non-contiguous nature of the MyCells range throws the function into a tailspin. A similar problem occurs if you try to use a non-contiguous range with the AVERAGEIF function:

=AVERAGEIF(MyCells, "<>0")

Since you can't use any of the functions you might want to use, you are left to rely on a bit longer formula to calculate the average. You can calculate the average of these five cells by applying a bit of "trickery" to your denominator, in this manner:

=(A1+C1+E1+G1+J1) / ((A1<>0)+(C1<>0)+(E1<>0)+(G1<>0)+(J1<>0))

The evaluation done on each cell in the denominator returns either a 1 (for True) or a 0 (for False) depending on whether the cell contains a non-zero value or not. This series of values is added together, providing the necessary count of non-zero cells for the denominator.

Notice that the discussion here has been all about the denominator in the formula, not the numerator. The reason is simple—you can add all five values into the numerator; zero values there don't really matter. The only place they matter is in the denominator, which is what makes calculating this average so tricky.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7845) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Averaging a Non-Contiguous Range.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using GEOMEAN with a Large List

When performing a statistical analysis on a large dataset, you may want to use GEOMEAN to figure out the geometric mean of ...

Discover More

Understanding Properties

Most of the objects that Windows makes available in its interface possess properties. These properties allow you to configure ...

Discover More

Creating and Saving a Spreadsheet

Before you can work with numbers, dates, and formulas, you need to create your Sheets spreadsheet. You can do so using the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

An Average that Excludes Zero Values

Excel allows you to use functions and formulas to analyze your data. One way you can analyze your data is to use the AVERAGE ...

Discover More

Determining a Simple Moving Average

A moving average can be a great way to analyze a series of data points that you've collected over time. Setting up a formula ...

Discover More

Averaging Values for a Given Month and Year

Excel is often used to analyze data collected over time. In doing the analysis, you may want to only look at data collected ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine more than 9?

2017-12-08 01:12:09

Samuel

If I have values in the following cells :B1,D1,F1,H1, & J1 and want excel to find the sum of the first three smallest values in any of the cells without considering the other cells left in the range (i.e A1,C1,E1,G1), in the calculation,
what formula will I have to use?


2017-12-05 19:20:10

JV

This worked perfectly and was exactly what I was looking for. I was trying to use AVERAGEIF with non-contiguous cells (and failing miserably)--I'm grateful you figured out this work-around.


2017-10-13 09:38:31

RMK

I used this to average all cells that contain numbers AND are greater than zero.B22 C22 D22 E22 F22 G22 H22 I22 J22 K22Minutes 0 Minutes 325 Minutes 445 Minutes 425 Minutes 50=SUM(C22:K22)/SUMPRODUCT(--(C22:K22<>0),ISNUMBER(C22:K22)*1)=(0+325+445+425+50)/(4)=311.25=Average(E22, G22, I22, K22)=311.25I'm learning how to use SumProduct and it's quite handy.


2017-07-31 10:58:09

M.

Nice tip. But wouldn't having all elements being averaged = 0 produce a divide by 0 error?


2017-07-31 03:05:56

Kevin

To record a late answer for "kw" the brackets around first cells addition probably haven't been entered as in =(A1+C1+E1+G1+J1)


2017-03-17 13:39:22

kw

This doesn't work at all. By your formula the average of 3 values "90, 90, 0" would be 180/180 = 100% When the actual answer should be 180/2=90


2017-01-27 15:36:26

Phil Pilkington

Thank you so much for your trick with replacing the AVERAGEIF function! I saw so many attempted solutions to this problem and none of them work as easily or elegantly as this!


2017-01-23 20:56:18

Shannon

Thanks very much for this! really needed this tip.


2017-01-11 12:08:18

Ryan Zbojovsky

Just thank you. Your site is unbelievably educational.


2016-12-30 15:54:11

Kevin Wampler

I never had to average non-contiguous cells and disclude 0% averages from my total average. Thanks for having this here. Very quick solution when I needed one!


2016-11-09 18:06:57

Alan

I would use this much simpler method:
=AVERAGEIF(A1:J1,">0")


2016-10-29 21:39:06

Sean

How can this be done on Google sheets? I can't figure it out and the formula posted here doesn't work on Google sheets.


2016-10-19 23:12:11

Guy

It does not work. I have double checked it. I get a 0 return. Working with 15 non-contiguous cells.


2016-10-18 11:30:41

Troy

How would i do this throwing out any cells that are below a certain percentage of the highest cell?


2016-07-31 15:59:13

Frank

Thank you for the understandable example.


2016-05-27 09:18:36

MAUREEN

Thank you! I searched all over for this answer. You had the best explanation!


2015-12-29 20:56:05

Taylor

Thank you soooo much!!!!


2014-12-29 16:17:52

Ed

This solution is very clever and works great for larger data sets.

https://colinlegg.wordpress.com/2013/05/04/conditional-average-on-non-contiguous-ranges-using-frequency/


2014-08-29 17:17:05

John

Nice fix, but only works if you have a small number of cells involved. For large quantities of data, makes it very difficult.


2014-06-19 11:42:47

Luke

Super helpful, thanks so much.


2013-09-20 18:42:56

deanna hall

I love you! Amazing tip. What if I only wanted to count cells that contained a number including 0 but if it was blank then do not count?


2013-08-18 11:22:47

Michael (Micky) Avidan

If I understoot, correctly' the situatuion - the 4 cells: B1,D1,F1,H1,I1 can be empty and/or hold zero(s).
If this is the case -the formulas, shown in the following link are shorter than the suggested in the tip:

http://tinypic.com/r/j0lj40/5

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL


2013-08-17 09:53:11

Taty

Great! I was just looking for something like this. Thanks.


2013-07-13 21:51:47

Juan

Wow, very interesting tip, amazing!


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.