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 December 30, 2013)

19

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

Making Sure Changes and Comments are Anonymous

When using Track Changes, Word normally notes the originator of a particular comment or change. This information can then be ...

Discover More

Reveal Codes in Word

While there are no true Reveal Codes in Word, as in WordPerfect, as they are vastly different word processors, there is a ...

Discover More

Freezing Worksheet Tabs

If you have a lot of worksheets in a workbook, you may wonder if you can "freeze" the position of some of those worksheet ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

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

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
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. 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 minus 5?

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.