Average non-adjacent cells (with criteria)

MonicaK

New Member
Joined
Jul 8, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am stuck on creating a formula for the below and would be really grateful for some assistance:

The table has 4 columns. Column A is text e.g. Apples, Bananas etc. Columns B,C,D are currency. More than one row in column A will contain Apples.

I want to find all rows which state Apple then sum the corresponding figures in columns B and D only and divide that sum by the count of Apples to obtain a correctly averaged figure.

I looked at averageif but couldn’t figure out how to use column B and D without C, and I wasn’t sure if the average would calculate correctly.

Any ideas?

Thanks,

Monica
 
To simplify matters, using the earlier example table of A to D if it now had a column E populated with either Frog or Goat then the next formula I need should calculate the average of B and D where E=Frog and A=Apple.

23 07 09.xlsm
ABCDEFGHI
1FruitAmt1Amt2Amt3AnimalFruitAnimalAverage
2Apple123GoatAppleFrog18
3Pear245Goat
4Apple367Frog
5Banana4811Frog
6Cherry51013Frog
7Banana61217Goat
8Apple71419Frog
9
Average
Cell Formulas
RangeFormula
I2I2=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2)),SUM(f)/ROWS(f))
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
23 07 09.xlsm
ABCDEFGHI
1FruitAmt1Amt2Amt3AnimalFruitAnimalAverage
2Apple123GoatAppleFrog18
3Pear245Goat
4Apple367Frog
5Banana4811Frog
6Cherry51013Frog
7Banana61217Goat
8Apple71419Frog
9
Average
Cell Formulas
RangeFormula
I2I2=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2)),SUM(f)/ROWS(f))
Sorry Peter, I missed this whilst banging my head against a brick wall! ha ha!

It works! Thank you so much for your help - you are a genius :)

Kind regards,

Monica
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0
Pls try

Cell I formula

=SUM(SUMIFS(OFFSET(B2:B8,,{0,2}),A2:A8,G2,E2:E8,H2))/COUNTIFS(A2:A8,G2,E2:E8,H2)
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
Sorry Peter, me again! Your formula below worked:

=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2)),SUM(f)/ROWS(f))

However, I now need to modify it to average the results from 3 tables (3 months in reality). Table 1 (ie. April) is on sheet A, table 2 (ie. May) is on Sheet 2 and table 3 (ie. June) is on sheet 3. The tables are set out identically on each sheet.
E.g. still using if Fruit = G2 and Animal=H2 and sum columns 2 and 4 but now of all 3 tables the divide it by the sum of rows of all 3 tables to obtain the average.

Hopefully this is not too tricky ;)

Thanks,

Monica
 
Upvote 0
Sounds like not an ideal layout. All the data in a single table with a Date and/or Month column would be a lot simpler.
However, you could try this.

Excel Formula:
=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2)),g,FILTER(CHOOSECOLS(Table2,2,4),(Table2[Fruit]=G2)*(Table2[Animal]=H2)),h,FILTER(CHOOSECOLS(Table3,2,4),(Table3[Fruit]=G2)*(Table3[Animal]=H2)),SUM(f,g,h)/(ROWS(f)+ROWS(g)+ROWS(h)))
 
Upvote 0
Sounds like not an ideal layout. All the data in a single table with a Date and/or Month column would be a lot simpler.
However, you could try this.

Excel Formula:
=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2)),g,FILTER(CHOOSECOLS(Table2,2,4),(Table2[Fruit]=G2)*(Table2[Animal]=H2)),h,FILTER(CHOOSECOLS(Table3,2,4),(Table3[Fruit]=G2)*(Table3[Animal]=H2)),SUM(f,g,h)/(ROWS(f)+ROWS(g)+ROWS(h)))
No, not the best layout but it’s monthly reports in different workbooks and I can’t change that. Thanks for the formula Peter but unfortunately if there is no match on one of the tables the formula doesn’t work. Not sure why because the formula sums f,g,h and divides by the sum of the f,g,h rows. Odd!
 
Upvote 0
Don’t worry Peter, for ease of calculation I have merged the 3 reports into 1 and used your original formula again. Thanks for your assistance though.
 
Upvote 0
if there is no match on one of the tables the formula doesn’t work.

for ease of calculation I have merged the 3 reports into 1 and used your original formula again.
That sounds like a much neater solution but the problem *could* have been avoided with this even longer formula
Excel Formula:
=LET(f,FILTER(CHOOSECOLS(Table1,2,4),(Table1[Fruit]=G2)*(Table1[Animal]=H2),NA()),g,FILTER(CHOOSECOLS(Table2,2,4),(Table2[Fruit]=G2)*(Table2[Animal]=H2),NA()),h,FILTER(CHOOSECOLS(Table3,2,4),(Table3[Fruit]=G2)*(Table3[Animal]=H2),NA()),SUM(IFNA(f,0),IFNA(g,0),IFNA(h,0))/(IFNA(ROWS(f),0)+IFNA(ROWS(g),0)+IFNA(ROWS(h),0)))

Thanks for your assistance though.
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,155
Members
449,098
Latest member
Doanvanhieu

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