Averageif?

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Is there such a function i.e. include a cell in the averaging if cell value is within a specified criteria?

Or perhaps somebody knows how to create a UDF for this?

Pls help.

Thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
PATSYS

Like this?

Formula in E1:=AVERAGE(IF(B1:B10>5,B1:B10))
confirmed with Ctrl+Shift+Enter
Mr Excel.xls
BCDEF
12Average of numbers > 57.66667
23
31
45
56
64
75
88
93
109
11
Average If
 
Upvote 0
You could use an array formula, or maybe a combination of SUMIF/COUNTIF, or SUMPRODUCT.

What's the criteria?
 
Upvote 0
what is the criteria ?? and the range, you could probably achieve this buy a combination of SUMIF and COUNTIF functions,

there will probably be a better way to do this but until we know more it would be hard to say
 
Upvote 0
It would be easy enought to make a function with soime VB script - is this something you'd be willing to do?

If so, it would probably go something like this:

Code:
max = 10 ' max holds the number of fields you want to process
total = 0 ' a running rally valid values summed together
count = 0 ' a running tally of the number of valid values

upperLimit = 100 ' the upper limit of a valid value
upperLimit = 50 ' the lower limit of a valid value

' Loop through a column of data that you want selectively averaged
for i = 0 to max
' See if a variable falls within the preset boundaries
if (range("firstCell").offset(i, 0).value > lowerLimit and range("firstCell").offset(i, 0).value < upperLimit) then
total = total + range("firstCell").offset(i, 0).value
count = count + 1
end if
next i

' Process the average
average = total / count
msgbox("Average of valid values is " & average)

Or something like that. It's also highly possible there's an Excel function that does this, but I'm a VB man and I always solve problems the needlessly complicated way... :D
 
Upvote 0
Thanks to all of you guys (man I love this forum).. :p

The criteria I have in mind is that if the cell value is either an error, zero or non numeric, then it should be excluded in the averaging. So if I have:

1
2
0
3
#DIV/0!

the average would be 2 (1+2+3)/3

I am going through the suggestion posted in this thread to see if I can fit it in to my problem.

Thanks again.
 
Upvote 0
If your range is A1:A5

=AVERAGE(IF(ISNUMBER(A1:A5),IF(A1:A5<>0,A1:A5)))

confirmed with CTRL+SHIFT+ENTER

...or a version requiring just ENTER....

=SUM(SUMIF(A1:A5,{"<0",">0"}))/SUM(COUNTIF(A1:A5,{"<0",">0"}))
 
Upvote 0
If your range is A1:A5

=AVERAGE(IF(ISNUMBER(A1:A5),IF(A1:A5<>0,A1:A5)))

confirmed with CTRL+SHIFT+ENTER

...or a version requiring just ENTER....

=SUM(SUMIF(A1:A5,{"<0",">0"}))/SUM(COUNTIF(A1:A5,{"<0",">0"}))
Fantastic.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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