Question

I need to calculate an average of 5 cells, but if a cell is blank or zero, it should neglect this value.

I am not able to get it to work with

=AVERAGEIFS(A10;B13;C5;D6;D8;"<>0")

Does anyone know the correct way to calculate this?

Was it helpful?

Solution 2

For an average of non-contiguous values, excluding any zeroes, try this formula

=IFERROR(SUM(A10;B13;C5;D6;D8)/((A10<>0)+(B13<>0)+(C5<>0)+(D6<>0)+(D8<>0));0)

or assuming no negative values you can use this

=IFERROR(SUM(A10;B13;C5;D6;D8)/INDEX(FREQUENCY((A10;B13;C5;D6;D8);0);2);0)

I used semi-colon delimiters as per question, change to commas if your regional settings demands

OTHER TIPS

You are looking for "Averageif": Excel showing averageif

Specifically, you want to use the range that includes possible blanks and then for the criteria use ">0"

=AVERAGEIF(C1:C5,">0")

Update: Non-contiguous ranges (not all working)

In the comments for this answer is a discussion about localization. My locale is United States (Excel 2010), so my delimiter between values passed to a function is the comma ,

Performing an averageif function on non-contiguous ranges is possible:

=AVERAGEIF(B1:B1:B3:B3:B5:B5:B7:B7,">0")

Excel 2010 comma-delimited averageif

For your locale, you might need to adjust delimiters, but the key thing is for the selection of individual cells, use the format "C1:C1:D4:D4" for the individual cells C1 and D4. The engine must be parsing the references as pairs.

I found myself working on something that I wanted to compute a formula only with the cells that are not empty. To accomplish this, I used the following:

=IF(COUNT(DATA),COMPUTE(DATA),"")

(where COMPUTE is the formula or computation you want to make, and DATA is the selection of data you have--in my case a column of data).

To make sure the cells are empty/zero/something when not a "normal value" you can use something like: =IF(CONDITION,NORMAL VALUE,"")

Example:

=IF(SUM(DATA)=0,"",SUM(DATA))

This will only sum the data if it is non-zero, and other cells will see this cell as blank when the data is zero.

Averageif using Indirect

After failing about three times with my other answer for this question, this answer should be ready for inspection:

=AVERAGEIF(INDIRECT({"b1","b3","b5","b7"}),">0")

Averageif and Indirect

Note: the localization of my Excel is United States Excel 2010. My delimiter is a comma, so adjust per your locale. If you would like to also average negative numbers, use "<>0" as the last value in the Averageif function.

How it works

The Indirect function makes a custom range of just the cells specified by (in this case) an array of strings. Averageif only adds items to its count if the criteria is met.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top