Averageif with multiple cells

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
955
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.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try

Excel Formula:
=LET(a,VSTACK(C8,C18,C26),AVERAGE(IF(a,a)))
 
Upvote 0
Hi Jason,

Thank you for the solution. The excel version in my organization currently does not have VSTACK formula. Is there an alternative?
 
Upvote 0
Just be aware that you are taking an average of an average and that is mathematically incorrect.
 
Upvote 0
Hi Alex,

I understand and we will review the formula for Table 1-3. Is there an alternative to Jason formula above since we currently don't have VSTACK ?
 
Upvote 0
Hi

I would suggest this setup with ONE table and a pivot table.
Mappe7
FGHIJK
1DateBranchRevenueBranchAverage of Revenue
201.01.2023Texas1500Iowa
301.01.2023TexasNew York1494,5
401.01.2023Texas1354Texas1444
501.01.2023Texas1478Total1472,857143
601.01.2023Texas
701.01.2023New York1500
801.01.2023New York1500
901.01.2023New York
1001.01.2023New York1478
1101.01.2023New York1500
1201.01.2023Iowa
1301.01.2023Iowa
1401.01.2023Iowa
1501.01.2023Iowa
1601.01.2023Iowa
Tabelle1
 
Upvote 0
This would give you the same result as @shift-del and be a correct average.
Excel Formula:
=AVERAGE(
       FILTER($C$2:$C$26,($C$2:$C$26<>"") * ISNUMBER($C$2:$C$26) * ISNUMBER($A$2:$A$26),""))

If you want to average the averages (not advised) then this should work.
Excel Formula:
=AVERAGE(
       FILTER($C$2:$C$26,($C$2:$C$26<>"") * ($C$2:$C$26<>0) * ($A$2:$A$26 = ""),""))
 
Upvote 0
Hi Alex,

Thank you for the solution. I didn't provide the exact data layout because I thought column A would not be used. My actual data layout is as below:

Book1
ABC
1Table 1
2DateBranchRevenue
31/1/2023Texas1,500
41/1/2023Texas
51/1/2023Texas1,354
61/1/2023Texas1,478
71/1/2023Texas
81/1/2023Texas1,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/1/2023New York1,495
18
19Table 3
20DateBranchRevenue
211/1/2023Iowa
221/1/2023Iowa
231/1/2023Iowa
241/1/2023Iowa
251/1/2023Iowa
261/1/2023Iowa0
27
28Table 4
291/1/2023Summary1325
Sheet1
Cell Formulas
RangeFormula
C8,C26,C17C8=IFERROR(AVERAGEIF(C3:C7,">0",C3:C7),0)
C29C29=AVERAGE(FILTER($C$2:$C$26,($C$2:$C$26<>"") * ISNUMBER($C$2:$C$26) * ISNUMBER($A$2:$A$26),""))


Is there anyway to modify the formula to derive the correct result using your suggestion which is not to average the average and therefore the correct result should be 1473?
 
Upvote 0
Hi,

You can test
Excel Formula:
=AVERAGEIFS(C8:C26,C8:C26,"<>0",A8:A26,"=")
 
Upvote 0
Hi,

I am getting the result as follows:

Book1
ABC
1Table 1
2DateBranchRevenue
31/1/2023Texas1,500
41/1/2023Texas
51/1/2023Texas1,354
61/1/2023Texas1,478
71/1/2023Texas
81/1/2023Texas1,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/1/2023New York1,495
18
19Table 3
20DateBranchRevenue
211/1/2023Iowa
221/1/2023Iowa
231/1/2023Iowa
241/1/2023Iowa
251/1/2023Iowa
261/1/2023Iowa0
27
28Table 4
291/1/2023Summary#DIV/0!
Sheet1
Cell Formulas
RangeFormula
C8,C26,C17C8=IFERROR(AVERAGEIF(C3:C7,">0",C3:C7),0)
C29C29=AVERAGEIFS(C8:C26,C8:C26,"<>0",A8:A26,"=")
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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