AverageIF that contain a text for visible/filtered cells only

floW_5

New Member
Joined
Jan 4, 2024
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Sorry, newbie here. I've been looking around (probably not hard enough) for the most appropriate formula with the AVERAGEIF function to work with filtered/visible cells only.

These are the two formula i am using atm which is working perfectly fine to show all data. But not when i filter out certain criteria because it keeps recognizing all cell within the table. Screenshot also attached.
=IFERROR(AVERAGEIF(AA:AA,"P",AD:AD),"")
and
=IFERROR(AVERAGEIF(AA:AA,"P",AE:AE),"")

I am truly sorry if this post have been made many times before me. I have tried a bunch of different solution from here & reddit and maybe I'm inputting something wrong but nothing seems to work for me yet.
 

Attachments

  • Screenshot 2024-01-04 173139.png
    Screenshot 2024-01-04 173139.png
    12.5 KB · Views: 37

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the MrExcel board!

To average filtered values try something like this. I recommend that you do not use whole column references.

Excel Formula:
=AGGREGATE(1,5,AD2:AD1000)
 
Upvote 0
Welcome to the MrExcel board!

To average filtered values try something like this. I recommend that you do not use whole column references.

Excel Formula:
=AGGREGATE(1,5,AD2:AD1000)
Hey, thank you for the super fast reply. Unfortunately this formula does not include the IF criteria. I'm trying to get it to average out only rows that contains the letter "P" with the second column number values. Hope this makes sense
 
Upvote 0
Welcome to the MrExcel board!

To average filtered values try something like this. I recommend that you do not use whole column references.

Excel Formula:
=AGGREGATE(1,5,AD2:AD1000)
Could you also please tell me why i shouldn't use the whole column reference?
 
Upvote 0
Unfortunately this formula does not include the IF criteria. I'm trying to get it to average out only rows that contains the letter "P" with the second column number values.
I thought that must have been the column that you were filtering on since that was the only column in your image with a filter drop-down showing. If you are filtering on that column then filtering for "P" should mean that the AGGREGATE formula would automatically only average the "P" values For example, here is my small example with nothing filtered.

24 01 04.xlsm
ZAAABACAD
1Average of col ADHdr1Hdr2Hdr3Hdr4
24P94
3F85
4P86
5F22
6P33
Av Filtered
Cell Formulas
RangeFormula
Z2Z2=AGGREGATE(1,5,AD2:AD1000)


Then filter col AA for "P" values

24 01 04.xlsm
ZAAABACAD
1Average of col ADHdr1Hdr2Hdr3Hdr4
24.333333333P94
4P86
6P33
7
Av Filtered
Cell Formulas
RangeFormula
Z2Z2=AGGREGATE(1,5,AD2:AD1000)


Could you also please tell me why i shouldn't use the whole column reference?
For some formulas it does not matter but others will do some calculation(s) for all 1 million plus cells in the column which can make the calculation very slow. If you only have a few hundred or a few thousand rows, why make Excel calculate all 1,048,576 cells (possibly several times, depending on the formula used)?

It looks like your image shows a formal Excel table at the left with only about 20 rows. Is that the case?

Perhaps you could tell us a bit more about exactly what you have, where it is, and what you are trying to do?
You might also give us some sample data to actually test with using XL2BB?
 
Upvote 0
Solution
I thought that must have been the column that you were filtering on since that was the only column in your image with a filter drop-down showing. If you are filtering on that column then filtering for "P" should mean that the AGGREGATE formula would automatically only average the "P" values For example, here is my small example with nothing filtered.

24 01 04.xlsm
ZAAABACAD
1Average of col ADHdr1Hdr2Hdr3Hdr4
24P94
3F85
4P86
5F22
6P33
Av Filtered
Cell Formulas
RangeFormula
Z2Z2=AGGREGATE(1,5,AD2:AD1000)


Then filter col AA for "P" values

24 01 04.xlsm
ZAAABACAD
1Average of col ADHdr1Hdr2Hdr3Hdr4
24.333333333P94
4P86
6P33
7
Av Filtered
Cell Formulas
RangeFormula
Z2Z2=AGGREGATE(1,5,AD2:AD1000)



For some formulas it does not matter but others will do some calculation(s) for all 1 million plus cells in the column which can make the calculation very slow. If you only have a few hundred or a few thousand rows, why make Excel calculate all 1,048,576 cells (possibly several times, depending on the formula used)?

It looks like your image shows a formal Excel table at the left with only about 20 rows. Is that the case?

Perhaps you could tell us a bit more about exactly what you have, where it is, and what you are trying to do?
You might also give us some sample data to actually test with using XL2BB?
Data1.xlsx
ABCDEFGH
3Avg1Avg2
45.897.21
5Column4Column5Column21Column22Pass or FailDifference1Difference2
634.65151.98P  
741.64448.92F  
878.79511.20P  
980.65519.6479.12634.78F1.020.82
109.84114.1163.95289.90P0.150.39
1131.87261.15P  
1286.01247.723.269.19P26.3826.95
1357.13265.97F  
14162.82994.8385.39462.84P1.912.15
15113.72231.42P  
16131.11879.80F  
1728.1491.5582.94169.86P0.340.54
18131.25879.808.1034.73P16.2125.34
1937.82123.59P  
2099.3399.43F  
2147.11227.55P  
2248.85276.3348.33250.68P1.011.10
235.2236.8231.29124.21P0.170.30
2482.23160.0889.06171.89P0.920.93
2561.49381.22F  
MASTER DATA
Cell Formulas
RangeFormula
G4G4=IFERROR(AVERAGEIF(F6:F1000,"P",G6:G1000),"")
H4H4=IFERROR(AVERAGEIF(F6:F1000,"P",H6:H1000),"")
G6:H25G6=IF(AND(B6<>"",D6<>""),(B6/D6),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F6:F1048576Cell Valuecontains "F"textNO
F6:F1048576Cell Valuecontains "P"textNO


Sorry had to play around a little more with the sheet and install xl2bb. But here is the sample data. hope this helps.
 
Upvote 0
Glad that you got XL2BB working. (y)

What about ..

and
So the formula in G4 works perfectly for what i want it to do with AVERAGEIF function. But when i do want to filter out some criteria which essentially removes certain data base what criteria is filtered out the value in G4 still shows the same average value. (Does not change)

The formula is to only average up value from "Difference1" IF column F contains the text "P".
 
Upvote 0
Glad that you got XL2BB working. (y)

What about ..

and
Yes its about 20 row for now and will be adding on a daily basis. Its an ongoing data collection.

=AVERAGEIF(F6:F1000,"P",G6:G1000)
Turn this formula to work on only visible cells when i filter out some data?
 
Upvote 0
What about ..
It looks like your image shows a formal Excel table at the left with only about 20 rows. Is that the case?
If so, what is the name of the table?
What columns does the entire table occupy?
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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