Averageif with multiple cells

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
922
Office Version
  1. 365
Hi,

I have the following table:

Book1
ABC
1Table 1
2DateBranchRevenue
31/1/2023Texas1,500
41/1/2023Texas
51/1/2023Texas1,354
61/1/2023Texas1,478
71/1/2023Texas
81,444
9
10Table 2
11DateBranchRevenue
121/1/2023New York1,500
131/1/2023New York1,500
141/1/2023New York
151/1/2023New York1,478
161/1/2023New York1,500
171,495
18
19Table 3
20DateBranchRevenue
211/1/2023Iowa
221/1/2023Iowa
231/1/2023Iowa
241/1/2023Iowa
251/1/2023Iowa
260
27
28Table 4
291/1/2023Summary
Sheet1
Cell Formulas
RangeFormula
C8,C26,C17C8=IFERROR(AVERAGEIF(C3:C7,">0",C3:C7),0)


Table 1-3 are the input tables. In Table 4,in cell C29, I am trying to calculate the average of cell C8, C17 and C26. The average should ignore the cell if the cell is blank or zero. In the above, the correct average is 1469. I tried using averageifs but I am not sure how to nest all the different cells in the formula. I appreciate any help.
 
Here is a possibility that doesnt involve redesign

Mr Excel Questions2.xlsm
ABCD
1Table 1
2DateBranchRevenue
31/1/2023Texas1500
41/1/2023Texas
51/1/2023Texas1354
61/1/2023Texas1478
71/1/2023Texas
81444
9
10Table 2
11DateBranchRevenue
121/1/2023New York1500
131/1/2023New York1500
141/1/2023New York
151/1/2023New York1478
161/1/2023New York1500
171494.5
18
19Table 3
20DateBranchRevenue
211/1/2023Iowa
221/1/2023Iowa
231/1/2023Iowa
241/1/2023Iowa
251/1/2023Iowa
26
27
28Table 4
291/1/2023Summary1469.25
Sheet7
Cell Formulas
RangeFormula
C8,C17C8=SUBTOTAL(1,C3:C7)
C29C29=SUMPRODUCT((--(B2:B28="")),C2:C28)/ SUM((--(B2:B28="")*(--(ISNUMBER(C2:C28)))))
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Here is a possibility that doesnt involve redesign

Mr Excel Questions2.xlsm
ABCD
1Table 1
2DateBranchRevenue
31/1/2023Texas1500
41/1/2023Texas
51/1/2023Texas1354
61/1/2023Texas1478
71/1/2023Texas
81444
9
10Table 2
11DateBranchRevenue
121/1/2023New York1500
131/1/2023New York1500
141/1/2023New York
151/1/2023New York1478
161/1/2023New York1500
171494.5
18
19Table 3
20DateBranchRevenue
211/1/2023Iowa
221/1/2023Iowa
231/1/2023Iowa
241/1/2023Iowa
251/1/2023Iowa
26
27
28Table 4
291/1/2023Summary1469.25
Sheet7
Cell Formulas
RangeFormula
C8,C17C8=SUBTOTAL(1,C3:C7)
C29C29=SUMPRODUCT((--(B2:B28="")),C2:C28)/ SUM((--(B2:B28="")*(--(ISNUMBER(C2:C28)))))

Ignore the subtotal statements, that was something I was testing out and forgot to undo.
 
Upvote 0
See if you can live with this. I have hidden #DIV0! errors with conditional formatting.
BTW I doesn't seem to make sense to have a line that is an average for the section and not having a label showing it an average.

20230205 Average of Averages kumara_faith.xlsx
ABC
1Table 1
2DateBranchRevenue
31/01/2023Texas1500
41/01/2023Texas
51/01/2023Texas1354
61/01/2023Texas1478
71/01/2023Texas
81/01/2023Texas1444
9
10Table 2
11DateBranchRevenue
121/01/2023New York1500
131/01/2023New York1500
141/01/2023New York
151/01/2023New York1478
161/01/2023New York1500
171/01/2023New York1494.5
18
19Table 3
20DateBranchRevenue
211/01/2023Iowa
221/01/2023Iowa
231/01/2023Iowa
241/01/2023Iowa
251/01/2023Iowa
261/01/2023Iowa#DIV/0!
27
28Table 4
291/01/2023Summary1472.05556
Sheet2
Cell Formulas
RangeFormula
C8,C26,C17C8=AGGREGATE(1,0,C3:C7)
C29C29=AGGREGATE(1,6,C2:C26)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C8Expression=ISERROR($C8)textNO
C17Expression=ISERROR($C17)textNO
C26Expression=ISERROR($C26)textNO
 
Upvote 0
Hi Alex,

Thank you for the solution. You are right on the row not having any proper label. My actually layout has a staff name column and a word Total as below. My apologies for not disclosing this earlier. May I know if the aggregate formula is a heavy formula ? The reason is I have about 60,000 rows to be filled with this formula. The initial averageifs formula did not cause any lag in the spreadsheet.

Book1
ABCD
1Table 1
2DateBranchStaff NameRevenue
31/1/2023TexasStaff11,500
41/1/2023TexasStaff2
51/1/2023TexasStaff31,354
61/1/2023TexasStaff41,478
71/1/2023TexasStaff5
81/1/2023TexasTotal1,444
9
10Table 2
11DateBranchStaff NameRevenue
121/1/2023New YorkStaff11,500
131/1/2023New YorkStaff21,500
141/1/2023New YorkStaff3
151/1/2023New YorkStaff41,478
161/1/2023New YorkStaff51,500
171/1/2023New YorkTotal1,495
18
19Table 3
20DateBranchStaff NameRevenue
211/1/2023IowaStaff1
221/1/2023IowaStaff2
231/1/2023IowaStaff3
241/1/2023IowaStaff4
251/1/2023IowaStaff5
261/1/2023IowaTotal#DIV/0!
27
28Table 4
291/1/2023SummaryTotal1,472
Sheet1
Cell Formulas
RangeFormula
D8,D26,D17D8=AGGREGATE(1,0,D3:D7)
D29D29=AGGREGATE(1,6,D2:D26)
 
Upvote 0
Given that you now have additional criteria to work with you can go back to your original section formulas and use a modified version of the filter formula.

20230205 Average of Averages kumara_faith.xlsx
ABCD
1Table 1
2DateBranchStaff NameRevenue
31/01/2023TexasStaff11500
41/01/2023TexasStaff2
51/01/2023TexasStaff31354
61/01/2023TexasStaff41478
71/01/2023TexasStaff5
81/01/2023TexasTotal1444
9
10Table 2
11DateBranchStaff NameRevenue
121/01/2023New YorkStaff11500
131/01/2023New YorkStaff21500
141/01/2023New YorkStaff3
151/01/2023New YorkStaff41478
161/01/2023New YorkStaff51500
171/01/2023New YorkTotal1494.5
18
19Table 3
20DateBranchStaff NameRevenue
211/01/2023IowaStaff1
221/01/2023IowaStaff2
231/01/2023IowaStaff3
241/01/2023IowaStaff4
251/01/2023IowaStaff5
261/01/2023IowaTotal0
27
28Table 4
291/01/2023SummaryTotal1472.85714
Sheet2
Cell Formulas
RangeFormula
D8,D26,D17D8=IFERROR(AVERAGEIF(D3:D7,">0",D3:D7),0)
D29D29=AVERAGE( FILTER($D$2:$D$26,($D$2:$D$26<>"") * ($D$2:$D$26<>0) * ($C$2:$C$26 <> "Total"),""))
 
Upvote 0
Hi Alex,

Thank you for your patience and that worked. If the users are still adamant to calculate the average of each branch average instead of the average of each branch staff, is there a way to accomplish this with the above layout?
 
Upvote 0
Yes but I have logged out for the night, so will have to give it to you tomorrow.
If you want to try yourself try changing the <> “Total” to = “Total”
 
Upvote 0
Yes but I have logged out for the night, so will have to give it to you tomorrow.
If you want to try yourself try changing the <> “Total” to = “Total”
I have tested this and it does what you are expecting
Excel Formula:
=AVERAGE(
       FILTER($D$2:$D$26,($D$2:$D$26<>"") * ($D$2:$D$26<>0) * ($C$2:$C$26 = "Total"),""))

At 60k records you might want to look at your overall process flow though.
It seems likely that you are inserting the section totals somehow. Nobody is going to be looking at 60k records, they are going to look at summaries. So rather than inserting section totals you are most likely better off going with @shift-del's pivot table suggestion or delve into Power Query or the Data Model and Power Pivot.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,097
Latest member
mlckr

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