Dynamic average_range by column text in AVERAGEIFS formula

g3lo18

New Member
Joined
Nov 2, 2013
Messages
35
Hi,

I am trying to obtain an average from multiple criteria using AVERAGEIFS function. The issue is I want to be able to specify the average range in a dynamic way based on column header name. I used index/match to specify the column name using header name for AVERAGEIF and it works like a charm. However, when using the same method in AVERAGEIFS it produces a #VALUE ! error. A simple example is attached. Please note there are two worksheets. Kindly advise if you have any solution to what I am trying to accomplish.

Many thanks!
g3lo18

worksheet "data example":

ABC
Tony123
Al123
Al123
Tony123
Lisa123
Lisa123
Tony123
Lisa123
Tony123

<tbody>
</tbody>

Main "Sheet2":

AVERAGEIF worksAVERAGEIFS does not
TonyTony + Lisa
A1=AVERAGEIF('data example'!A:A,"Tony",INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0)))#VALUE !=AVERAGEIFS(INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0)),'data example'!A:A,"Tony",'data example'!A:A,"Lisa")
B2=AVERAGEIF('data example'!A:A,"Tony",INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A4,'data example'!$A$1:$D$1,0)))#VALUE !=AVERAGEIFS(INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A4,'data example'!$A$1:$D$1,0)),'data example'!A:A,"Tony",'data example'!A:A,"Lisa")
C3=AVERAGEIF('data example'!A:A,Sheet2!$B$2,INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A5,'data example'!$A$1:$D$1,0)))#VALUE !=AVERAGEIFS(INDEX('data example'!$A$1:$D$10,0,MATCH(Sheet2!$A5,'data example'!$A$1:$D$1,0)),'data example'!A:A,"Tony",'data example'!A:A,"Lisa")

<tbody>
</tbody>


Thank you!
 
Last edited:
I need to be able to average "is not" on multiple criteria as the sample data I provided you with is simplified. The actual data has over 200 unique variables, and if I name each one, it will take forever. I need to be able to say average 198 variables and avoid 2 ofthem. Or, average 197 variables, and avoid 3 of them, etc.

If it is Tony it cant also be Lisa nor can it be Frank. Give examples of cell values and whether you want them counted in the average or not.
 
Last edited:
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I tried this, and this does not work with <> functions. Here is what I did:

=SUMPRODUCT(((A2:A10<>"*Tony*")+(A2:A10<>"Lisa"))*(B1:D1=F2)*(B2:D10))/SUMPRODUCT(((A2:A10<>"*Tony*")+(A2:A10<>"Lisa"))+0)

Provides the wrong average. I checked manually to see if it works.

Try this:

data example

ABCDEFG
1ABCAVERAGEIF
2Tony123A
3Al123Tony
4Al123Lisa1.7142857
5Tony223
6Lisa123
7Lisa223
8Tony223
9Lisa323
10Tony123

<tbody>
</tbody>

CellFormula
G4=SUMPRODUCT(((A2:A10=F3)+(A2:A10=F4))*(B1:D1=F2)*(B2:D10))/SUMPRODUCT(((A2:A10=F3)+(A2:A10=F4))+0)

<tbody>
</tbody>

<tbody>
</tbody>


 
Last edited:
Upvote 0
This will do the average where the cell contains neither Lisa nor Tony

=AVERAGE(IF((NOT(ISNUMBER(SEARCH("Lisa",$A$2:$A$10))))*(NOT(ISNUMBER(SEARCH("Tony",$A$2:$A$10)))),INDEX('data example'!$A$2:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0))))
 
Upvote 0
Thanks for the continue guidance. I tried this, when I don't click ctrl+shift+enter it works but displays the same number irrelevant of which column name you use. If I do an array (cntrl+shift+enter) it shows #N/A. :S

This will do the average where the cell contains neither Lisa nor Tony

=AVERAGE(IF((NOT(ISNUMBER(SEARCH("Lisa",$A$2:$A$10))))*(NOT(ISNUMBER(SEARCH("Tony",$A$2:$A$10)))),INDEX('data example'!$A$2:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0))))
 
Upvote 0
Another option is to create a pivot table, in it you can filter by one several items and get the average of A, B and C at the same time

560e47d40041265aa0fac71225e6f2fc.jpg
 
Upvote 0
I tried this, and this does not work with <> functions. Here is what I did:

=SUMPRODUCT(((A2:A10<>"*Tony*")+(A2:A10<>"Lisa"))*(B1:D1=F2)*(B2:D10))/SUMPRODUCT(((A2:A10<>"*Tony*")+(A2:A10<>"Lisa"))+0)

Provides the wrong average. I checked manually to see if it works.


For that you need another type of formula, your requirement is to average Tony and Lisa. Not any combination.
 
Upvote 0
I think it worked, I had one issue there I made. Thanks so much!

This will do the average where the cell contains neither Lisa nor Tony

=AVERAGE(IF((NOT(ISNUMBER(SEARCH("Lisa",$A$2:$A$10))))*(NOT(ISNUMBER(SEARCH("Tony",$A$2:$A$10)))),INDEX('data example'!$A$2:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0))))
 
Upvote 0
I run into a problem using this formula counting blanks. Is there a way to ensure this formula does not account for blanks?

This will do the average where the cell contains neither Lisa nor Tony

=AVERAGE(IF((NOT(ISNUMBER(SEARCH("Lisa",$A$2:$A$10))))*(NOT(ISNUMBER(SEARCH("Tony",$A$2:$A$10)))),INDEX('data example'!$A$2:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0))))
 
Upvote 0
=AVERAGE(IF(($A$2:$A$10<>"")*(NOT(ISNUMBER(SEARCH("Lisa",$A$2:$A$10))))*(NOT(ISNUMBER(SEARCH("Tony",$A$2:$A$10)))),INDEX('data example'!$A$2:$D$10,0,MATCH(Sheet2!$A3,'data example'!$A$1:$D$1,0))))
 
Upvote 0

Forum statistics

Threads
1,215,180
Messages
6,123,502
Members
449,100
Latest member
sktz

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