How to calculate an average using only certain rows of data, based on whether a text word in the column header appears in any cell along that row?

exceldata

New Member
Joined
Mar 2, 2016
Messages
44
Hello,

I would like to use a formula to calculate the Average of the numbers in the first column of data (Column Header:"Red"), but I only want to use the data in cells that are in a row that contains the Header text somewhere in that row. So for Column Header Red, I would like to use the first number, 2, the second number, 4, skip the third number, 5, use the forth number, 1, and skip the last number, 3.

I would like to enter this formula along the row where I have the text showing in a red color in this post.

Could anyone help me with this? It would be greatly appreciated!

[TABLE="width: 860"]
<tbody>[TR="bgcolor: transparent"]
[TD][/TD]
[TD]Red[/TD]
[TD]Blue[/TD]
[TD]Green[/TD]
[TD]Yellow[/TD]
[TD]Orange[/TD]
[TD]Color Choice 1[/TD]
[TD]Color Choice 2[/TD]
[TD]Color Choice 3[/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Respondent 1[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]1[/TD]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]Red[/TD]
[TD="bgcolor: transparent"]Yellow[/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Respondent 2[/TD]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]1[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"]Blue[/TD]
[TD="bgcolor: transparent"]Red[/TD]
[TD="bgcolor: transparent"]None[/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Respondent 3[/TD]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Respondent 4[/TD]
[TD="bgcolor: transparent"]1[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]Orange[/TD]
[TD="bgcolor: transparent"]Green[/TD]
[TD="bgcolor: transparent"]Red[/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Respondent 5[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]1[/TD]
[TD="bgcolor: transparent"]Green[/TD]
[TD="bgcolor: transparent"]None[/TD]
[TD="bgcolor: transparent"]Purple[/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Average B2:B6[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]2.4[/TD]
[TD="bgcolor: transparent"]3.2[/TD]
[TD="bgcolor: transparent"]3.4[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR="bgcolor: transparent"]
[TD]Average for all Respondents who chose the Column Header Color in any Column Choice Option, G through I



I apologize in advance for the appearance of this table. I read the instructions and downloaded the tools but could not figure out how to generate a table that would post properly in this comment box.[/TD]
[/TR]
</tbody>[/TABLE]

Thank you!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Assuming the first column is column A try this:
=SUMIF($F2:$F6,A1,A2:A6)+SUMIF($G2:$G6,A1,A2:A6)+SUMIF($H2:$H6,A1,A2:A6)/(COUNTIF($F2:$F6,A1)+COUNTIF($G2:$G6,A1)+COUNTIF($H2:$H6,A1))
 
Upvote 0
Thank you, offthelip. The column with header Red is column B. So I took your formula and changed all of the A's to B's, and changed F,G,H into G, H, I. But it gave me this answer: 6.333.

The correct answer should be 2.333, so I'm not sure what needs to be changed.

For some clarification, Aladin:

The 7th row down is marked "Average B2:B6", and it has averages for the five numbers above it. I want to calculate that basic average, but then in the next cell below it I want to calculate the average of only numbers that appear in a row that also contains the color text that matches the text in the column header. So in column B (Red) I want it to average 2,4, and 1, because the word "Red" appears in their rows off to the right.


Thanks for your input!
 
Upvote 0
Could this be easily amended to calculate an average using the opposite criteria - only numbers that do NOT have the column header word appearing in their row?
 
Upvote 0
Could this be easily amended to calculate an average using the opposite criteria - only numbers that do NOT have the column header word appearing in their row?

Control+shift+enter, not just enter, and copy across:

=AVERAGE(IF(IF(MMULT(($G$2:$I$6=B$1)+0,TRANSPOSE(COLUMN($G$2:$I$6)^0)),0,1),B$2:B$6))
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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