AVERAGEIFS with criteria to include and with criteria to exclude at the same time

qwzky

Board Regular
Joined
Jul 22, 2021
Messages
53
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi! I've been trying for two days to get this out, and now I'm starting to think that what I want is actually impossible. Maybe I'll find my luck here :)

I have the following table, where I included my criteria in red:

SC-uri automate REDONE4 (test, ă văd dacă merge să lucrez in sheets separate).xlsm
BCDEFGHIJ
3StudentsGrade 1Grade 2Grade 3Grade 4Grade 5Overall pointsAverage
4Not appliable yet#VALUE!
5Mark457755don't calculate because Grade1<5 AND because OverallPoints<6
6John66676calculate because Grade 1 ... Grade 5 >=5 AND because OverallPoints>=6 AND ignore Grade 5 (empty cell)
7Anneabs565don't calculate because she was absent at Grade1 AND because she doesn't have OverallPoints
8James101010105don't calculate because OverallPoints<6 AND ignore Grade 5 (empty cell)
CIORNĂ
Cell Formulas
RangeFormula
J4J4=AVERAGEIFS(C5:H5,C5:G5,">=5",H5,">=6")


I have tried to use COUNTIF and AND, but still can't get it work.

My criteria are:

1. Numbers from Grade 1 to Grade 5 should be higher than 4 for average (if not, leave the average cell empty)
2. Numbers in OP should be higher than 5 (if not, leave the average cell empty)
3. If OP has empty cells, don't calculate average at all.
3. In calculating average, look for text (if there is text, leave the average cell empty)
4. In calculating average, ignore empty cells (for instance, John's average should be: (6+6+6+7+6)/5, not divided by 6)

As you see, I have 2 criteria that are somewhat contradictory: ignore empty cell in a range, but take into account the empty cell in another range.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is this what you want?
Book1
BCDEFGHI
3StudentsGrade 1Grade 2Grade 3Grade 4Grade 5Overall pointsAverage
4Not appliable yet
5Mark457755 
6John666766.2
7Anneabs565 
8James101010105 
Sheet1
Cell Formulas
RangeFormula
I5:I8I5=IF(AND(H5>=6,MIN(C5:G5)>=5,COUNT(C5:G5)=COUNTA(C5:G5)),AVERAGE(C5:H5),"")
 
Upvote 0
Solution
You made me happy! :) Seeing these complexe formulas coming out from you so fast is like watching magic tricks to me :)
 
Upvote 0
Also, is there any way I can appreciate you? some rating stars or reviews? :D
 
Upvote 0
You're welcome, thanks for the feedback!

Most of us are simply here to help others, a quick thank you as appreciation enough. That said, a quick click on the like button at the bottom right of a helpful post is always welcome :)
 
Upvote 0
Also, how to return results only if there are 2 numbers? If there is only one or none, the returned result should be empty cell.

SC-uri automate REDONE4 (test, ă văd dacă merge să lucrez in sheets separate).xlsm
IJKL
82MATEIU7,127,007,06
83MOLDOVEANU6,94 6,94
84PAPUC M  #DIV/0!
FORMULE ȘI DATE
Cell Formulas
RangeFormula
J82:K84J82=IF(J57=0,"",J57)
L82:L84L82=AVERAGEIF(J82:K82,"<>")
 
Upvote 0
You can use COUNT to identify how many cells contain numbers, it will ignore empty cells, text, and formulas that show a blank.
Excel Formula:
=IF(COUNT(J82:K82)=2,AVERAGE(J82:K82),"")
 
Upvote 0
Thank you for your heart and brain :) Now, I can go to the next phases of my project. I can't believe this place, the people on this this site really exist. Hope I can help other in the future (when I learn more about Excel) :) Thank you again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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