averagifs of two products only when found together in same location

nuest12

New Member
Joined
Nov 12, 2015
Messages
8
I have been trying to figure out how to compare the averages of two corn hybrids only when they are found in the same location. Here is an example of some data

A B C

Location Hybrid Yield

1 Morris 197-68stx 215
2 Morris 203-01stx 220
3 Morris 199-29stx 200
4 Morris 205-19stx 225
5 Hancock 197-68stx 200
6 Hancock 203-01stx 190
7 Hancock 205-19stx 210
8 Benson 197-68stx 180
9 Benson 203-01stx 200
10 Willmar 197-68stx 220
11 Willmar 203-01stx 210
12 Willmar 205-19stx 215

In this case I would like to find the average of the hybrid 203-01stx and compare it to the average of the hybrid 205-19stx but only when they are both found in the same location. In the example above we would not take the average of the Benson location because the 205-19stx hybrid was not planted there. I have about 100 locations that I am trying to take averages from. It would also be nice to be able to switch the hybrids I was comparing without having to drastically change my formula. I.E. comparing 197-68stx vs. 203-01stx. I have tried a few different things such as taking the average(averageifs(c1:c12,a1:a12,a1,b1:b12,b2),averageifs(c1:c12,a1:a12,a5,b1:b12,b2),averageifs(c1:c12,a1:a12,a10,b1:b12,b2))

This gives me the average of the 203-01stx hybrid in each location it is present with the 205-19stx hybrid and then I can find the average of the 205-19stx hybrid by writing the same formula. However this requires me to go through all the data to find the locations where both hybrids are present. I am looking for a simpler and cleaner way of making this possible.

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
ABCDEFG
LocationHybridYield
Hybrid1Hybrid2
Morris197-68stx203-01stx205-19stx
Morris203-01stx
Morris199-29stxAverages
Morris205-19stx
Hancock197-68stx
Hancock203-01stx
Hancock205-19stx
Benson197-68stx
Benson203-01stx
Willmar197-68stx
Willmar203-01stx
Willmar205-19stx

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]215[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]220[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]200[/TD]
[TD="align: right"][/TD]

[TD="align: right"]206.6667[/TD]
[TD="align: right"]216.6667[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]225[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]200[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]190[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]210[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]180[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"]200[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]

[TD="align: right"]220[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]

[TD="align: right"]210[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]

[TD="align: right"]215[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

F5: =AVERAGE(IF(COUNTIFS(A:A,A3:A14,B:B,$F$3)*COUNTIFS(A:A,A3:A14,B:B,$G$3),IF(B3:B14=$F$3,$C$3:$C$14)))

G5: =AVERAGE(IF(COUNTIFS(A:A,A3:A14,B:B,$F$3)*COUNTIFS(A:A,A3:A14,B:B,$G$3),IF(B3:B14=$G$3,$C$3:$C$14)))

Those are array formulas, when you enter them in the formula bar, change the references to match your sheet, then confirm with Control+Shift+Enter, not just Enter.

Let me know how they work for you.
 
Upvote 0
This should do it:

=SUM(IF(COUNTIFS(A:A,A3:A14,B:B,$F$3)*COUNTIFS(A:A,A3:A14,B:B,$G$3),IF(B3:B14=$F$3,1)))
with Control+Shift+Enter
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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