countif funtction after filtering

Copiloc

New member
Joined
Feb 10, 2016
Messages
6
Reaction score
0
Points
0
My entire database is filtered several times. In one of the last steps I need to hide all data from companies who are not providing at least 5 datasets (5 years of data). So I used "countif" to see how many times a company is featured in my database. But only those companies who remain after the previous filters are relevant to me.
So some companies, before applying a filter, are featured 5 times or more, but after applying all filters they are no longer and therefore have to be dismissed. However, "countif" always counts all data, also those which are hidden because of the filters.
I tried a weird function that I found in a german forum via google, which btw was the only one i found, but that one didn't work out for me: =SUMPRODUCT(PARTIALRESULT(3;INDIRECT("C"&ROW(2:999)))*(C2:C999="X"))

I attached an extract of my list of companies and the 2 functions i used. (which are "countif" for the frequency and "if" for the company name output column)
I applied a filter to "Assets" which only leaves 2 observations for "Steyr-Daimler-Puch-AG", but the frequency still says 9 because it still considers the hidden data. I need it to update though after applying the filter, so that it will show an empty cell in the "Company Name*" column.
 

Attachments

  • nms2.xlsb
    10.8 KB · Views: 16
How about if you build in the Assets filter number into your COUNTIF formula (or, in this case COUNTIFS)?

try changing column D formula to:

=COUNTIFS($B:$B,B3,$A:$A,">=10")
 
Cross-posted at Excelforum.com

Please read this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
 
Last edited:
First of all. Sorry for the cross-post. Unfortunately I don't see an edit button and also I cannot post a link cause I'm a new member. excelforum.com/excel-formulas-and-functions/1126058-countif-function-after-filterting.html#post4314030

Second, thanks for the answers.
@NBVC: It works. Since I have 10 filters in my database I would have to include all of them, but I can see it work. So thank you very much :)

@Pecoflyer: As far as I can see this is exactly the function that didn't work for me or well maybe I didn't make it work :D (I think i translated some functions wrong in the original post)
Here's the function again: =SUMPRODUCT(SUBTOTAL(103;OFFSET($B$3;ROW($3:$47)-3;))*($B$3:$B$47=B44))
Could you explain the function to me, like what the respective parts of it do. Especially the one before the * doesn't make sense to me.
And also, can I change the function so that it considers every cell in the column, like this: B:B instead of B3:B47

It worked too, so thank you very much as well!
 
Last edited:
ROW($3:$47) creates an array of numbers 3,4,5....47
From which we subtract 3 as we started the OFFSET in the 3rd row (B3) , giving 0,1,2,...44
OFFSET now looks at B3(+0), B4 : B3 (+1), etc
103 is the code SUBTOTAL needs for COUNTA hidden values excluded
and SUBTOTAL returns an array of 1's (not hidden) and 0's (hidden)
which multiplied by the $B$3:$B$47=B44 part gives us 2

To see it at work, select the part you want evaluated in the formula bar and press F9

I wouldn't recommend using B:B, as you see from the explanation above the functions need to know where to start. But B3:B1000 might do

( also B :B will not work with SUMPRODUCT in pre 2007 XL versions)

NB if you have 2010 or later, you can also use the AGGREGATE function instead of SUBTOTAL.It has some nice features
 
Last edited:
Thank you for the explanation, I understand it now. I adjusted the function for my first databse which has nearly 1700 rows of data and it worked. It took Excel a bit to reapply all the filters at once, but it worked and hopefully does for the ones exceeding the 10000, 20000 and 30000 threshold too ;)
Thank you for helping me out, you really saved me :D
 
Happy to say that the function works perfectly. Excel is loading constantly, though. While I understand that it has to update all cells with the function in when something gets changed, I really don't get why it has to do the same thing whenever I open the file? Even when the file is opened and I open another Excel file it computes something? Also when I press enter in another Excel file it starts computing.
Probably a weird question, but is this normal?
 
Back
Top