Any way to get a count of filtered rows?

COUNTA() works fine … but gives the total count of all rows in a given table.


I need to determine the number of rows which result after a filter has been applied.


It appears that Excel can do this via the SUBTOTAL() function, with a specified parameter (see https://support.microsoft.com/en-us/kb/244789) But, unfortunately, Numbers doesn't offer this function.

Is there any way to do this in Numbers? Would I need to pursue an extremely-convoluted "IF" function, incorporating the entire set of filter criteria + the count behaviors, within that formula?

MacBook Pro with Retina display, OS X Yosemite (10.10.5)

Posted on Jan 15, 2016 7:42 PM

Reply
8 replies

Jan 15, 2016 11:24 PM in response to Brian Latimer

Hi Brian,


While Numbers 3 doesn't support categories, it's still possible (fairly easy, actually) to get category totals or counts. You'll want to do this on a separate table.

Here's an example, using the same categories as above in column B, but with some data aded in column C. The data table is named "Data," the summary table, reporting the count and total for each category, in named Summary. For ease of in head calculations, the 'amount' for every entry in a category is the position of that letter in the alphabet, making the total count x 1 for a, count x 2 for b, etc.

User uploaded file

Data has no formulas. All data shown (categories and amounts) can be considered as directly entered from the keyboard, or pasted in from another source.


Summary has two formulas, one to count the number of entries in each category, the other to total the amount entered in each category. The category list is entered directly in column A. Categories must be exact matches of those in column B of Data.


Summary::B2: =COUNTIF(Data :: $B,A)

English: Count all of the entries in Data, Column B that match the entry in this row of Column A of this table.

Fill this formula down from B2 (of Summary) to the last row of the table.


Summary::C2: =SUMIF(Data :: $B,A,Data :: $C)

English: Check the category data in column B of Data. If the category on a row matches the value in this row of column A of this table, include the value in that row of column C of Data in the total calculated on this row.

Fill this formula down from Summary::C2 to the last row of column C of this table.


NOTE that the calculations do not depend on the table being sorted into any particular order.


For another example, open a new document from the Personal Budget template included with Numbers, and examine the category totals calculations in that document.


Regards,

Barry

Jan 16, 2016 12:00 AM in response to Brian Latimer

Hi Brian,


I want to restate, along with Barry, the usefulness of COUNTIF() AND COUNTIFS(). Whatever filters you are using should not be too difficult to recreate with these functions.


The other thing that Barry suggests is the use of summary tables. I have grown to love these. I can pull data into a summary table and have it already sorted. I might put a filter on it to hide unneeded rows.


quinn

Jan 16, 2016 12:32 AM in response to Brian Latimer

Hi Brian,


I see that COUNTIF is recommended by Barry and quinn 🙂.


A table with a Header Row and a Footer row.

Column A was simply my attempt to see what a filter would show.

Formula in A2 (and Fill Down) =ROW()−1

Formula in Footer Cell A9 =MAX(A)

User uploaded file

Suppose that one of the Filter rules is to show rows where column B equals a,

Formula in B2 (and Fill Down) =IF(B2=B$1,1,0)

Using B$1 makes it easy to change the formula, if that is required, by typing a new value.


Formula in Footer Cell B9

=COUNTIF(C,1)

User uploaded file

Formula in C1 ="="&B1&"?"


Now apply the filter(s) (and hide column C if you wish)

User uploaded file

That should work if you have a number of filters linked by AND, but not if they are linked by OR.


Regards,

Ian

Jan 15, 2016 8:57 PM in response to Brian Latimer

Hi Brian,


I don't know if this is a glitch in the program but this may work for you. My column E has 9 entries. When the filter is off this is recognized by COUNTA. When I apply the filter I see the result below. I haven't been able to get a formula in the table that will reflect this so if you need to use the result in a formula you would need to use COUNTIF or COUNTIFS.

User uploaded file


quinn

Jan 17, 2016 2:01 AM in response to Brian Latimer

Hi Brian,


Have a play with this https://www.dropbox.com/s/isbcm5jkqhmn6i0/Dynamic%20Filter.numbers?dl=0


User uploaded file

The Conditional Highlighting in Column B is not necessary for this to work. I added it for clarity.

Formula in C1 ="="&"'"&B$1&"'"&"?"

Formula in C2 (and Fill Down) =IF(B=B$1,"Yes","No")

Formula in Footer Cell A11 ="Body Rows matching "&"'"&B$1&"'"

("'" is double quote, single quote, double quote)

Formula in Footer Cell B11 =COUNTIF(B,B$1)


Now type (or Copy and Paste) a new value into B1

User uploaded file

Filter Rule is this

User uploaded file

Filtering by Column C (currently named by C1 ='a'?) but when you enter a new value in C1, Numbers magically changes the Filter rule to whatever is in C1

User uploaded file

Now apply the Filter (Tick the Checkbox to the right of Filters)

User uploaded file

With the Filter on, enter a new value in B1

User uploaded file

Upper and Lower Case (b or B) do not matter in this example.


Cell Data Format is magically handled too:

User uploaded file


Thank you for the question. Playing with it taught me lots about the charm of Numbers.


Regards,

Ian.

Jan 15, 2016 9:05 PM in response to Brian Latimer

Hi Brian,


Still living in the past here, so what works below in Numbers '09 may or may not be available in Numbers 3.

Select the table, then click Reorganize (in Numbers '09, a button in the bar above the workspace). Set up automatic categories on one column (B in this case) using the Reorganize dialogue:


User uploaded file

Sort the table on the column containing the categories to lines from each category together.

Numbers will insert category row for each chnge in the content of column B.

Click on the cell in column B in any of the new Category rows, then click on the small triangle that appears at the right side of the cell to view the contextual menu.

Choose an appropriate item to display in these rows (and in this column). Since the data in the column is all text, I chose "Count. Results can be seeen in the category rows for categories d, e, f, and g, which are neither off-screen nor covered by the menu.


The disclosure triangle in the Column A category rows allows you to hide the data rows forthat category. The count (or other calculartion continues to show in column B).


User uploaded file


Regards,

Barry

Jan 15, 2016 9:05 PM in response to t quinn

Yep, I had seen that the dynamic "quick calculations" which are offered, will update as I select different cells, or apply different filters. But, I was hopeful that I could actually get that dynamic value entered into a cell, without the need for the manual selection action.


Note also that if I drag that offered "COUNTA" calculation to another cell, it is explicitly indicating only the currently-selected cells - e.g. "=COUNTA(E2,E4,E5,E9,E10)" … which obviously won't work, if this data is intended to possibly change.


Ah, well - an opportunity for enhancement of the app, I suppose.


Thanks for the response!

Jan 15, 2016 9:08 PM in response to Barry

Ooh - intriguing. Unfortunately, they seem to have killed off "Categories" in the more-recent versions of the app. ** Can anyone refute this, or correct me on how we might regain this functionality?


But, I might be able to build a set of "categorized" entries, and pursue subtotals of them a different way. Not as direct of a result as I was hoping for, but perhaps a workaround for the time being.

Thanks!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Any way to get a count of filtered rows?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.