How to Count Filtered Rows in Excel?

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

Last updated

If you want to count filtered rows in Excel, you can do that using the SUBTOTAL function.

The SUBTOTAL function allows you to perform a regular count on a column with the ability to exclude those rows that have been filtered out.

In this short tutorial, I will show you how to use the SUBTOTAL function to count filtered rows in Excel, and another visual way to quickly identify the total number of filtered rows.

I’ll also cover the Total Row in Excel Tables, and a formula that counts only the filtered rows that meet a condition (something COUNTIF can’t do).

Follow along with the example file

Count Filtered Rows Excel.xlsx

Download

Count Filtered Rows Using SUBTOTAL Function

Below is a data set where I have the employee’s name in column A, the department name in column B, and the location in column C, and I want the count of rows left after filtering in cell C12.

Employee list with name, department, and location, with empty SUBTOTAL 3 and SUBTOTAL 103 count cells below

I have now applied a filter to this data set and filtered out the rows where the department name is Finance. So you get the dataset as shown below.

Employee list filtered to hide the Finance rows, leaving six visible rows

Now I want to get the count of filtered rows only.

Here is the SUBTOTAL formula that will give me the count of only those rows that are visible after the filtering is applied:

=SUBTOTAL(3,B2:B10)
SUBTOTAL formula with 3 counting the six visible rows in the filtered employee list

The above formula gives us 6, which is the total number of rows that we have left after we have filtered the data set.

In the above SUBTOTAL function, we have used two arguments:

  • 3 as the first argument – the first argument of the SUBTOTAL function always needs to be a numeric value that tells the function what kind of operation it needs to do on the following range. Using 3 here tells the function that it needs to give the count of the range (specified in the second argument) and skip the rows that have been filtered out.
  • B2:B10 – this is the range on which the count is done.

Function number 3 does a COUNTA, which counts every cell that isn’t empty. So pick a column that has a value in every row (like the name or department column), because a blank cell in that column would not be counted.

Apart from the above formula, you can also use the below SUBTOTAL formula:

=SUBTOTAL(103,B2:B10)
SUBTOTAL formula with 103 also returning 6 for the filtered employee list

The above formula also gives us 6. When you use 103, it also ignores rows you have hidden by hand (i.e., it does not count the hidden rows), even in an unfiltered dataset.

Note that these two arguments in the formula (3 and 103) work exactly the same when you use them with a filtered dataset. I cover the one case where they differ in the next section.

Also read: Select Visible Cells in Excel

SUBTOTAL 3 vs 103: Counting Rows You Hid Manually

The difference between 3 and 103 only shows up when you hide rows yourself (right-click the row number and choose Hide), instead of filtering them out.

Below is the same employee list, where I have hidden rows 5 and 9 by hand (no filter applied), and I want to count the rows that are still visible.

Employee list with rows 5 and 9 hidden by hand and no filter applied

Here is the formula with 3 as the first argument:

=SUBTOTAL(3,B2:B10)
SUBTOTAL formula with 3 returning 9 because it still counts the rows hidden by hand

This gives us 9, even though only 7 rows are visible. When you use 3 and there is no filter, rows you hid manually are still counted.

Now here is the same formula with 103:

=SUBTOTAL(103,B2:B10)
SUBTOTAL formula with 103 returning 7 because it skips the rows hidden by hand

This gives us 7, because 103 skips the rows you hid by hand.

But if you’re still confused about these two formulas, the table below should clear any confusion.

Dataset ConfigurationUsing 3Using 103
Rows not hidden and not filteredCounts all rowsCounts all rows
Rows hidden manually, no filterHidden rows are countedHidden rows are not counted
Rows filtered (none hidden manually)Only visible rows are counted. Filtered-out rows are not countedOnly visible rows are counted. Filtered-out rows are not counted
Filter applied, then more rows hidden manuallyOnly visible rows are counted. Filtered-out rows and hidden rows are not countedOnly visible rows are counted. Filtered-out rows and hidden rows are not counted

In short, if you have a filtered dataset, both 3 and 103 will give you the same result.

The order you do things in also matters here. If you hide some rows by hand and then apply a filter, Excel shows those rows again if they match the filter, and then they get counted like any other visible row.

Since 103 counts only the rows you can see in every case, it’s the safer choice if you’re not sure how the rows got hidden.

Count Filtered Rows in an Excel Table (Total Row)

The above formulas would work with Excel Tables as well. But if your data is in a Table, there is an even easier way, as the Table’s Total Row can give you this count without typing any formula.

Below is the same employee list converted into an Excel Table, with the Finance rows filtered out, and I want the count of the visible rows in the Total Row below it.

Employee list as an Excel Table with the Finance rows filtered out

Here are the steps to add a count of filtered rows using the Total Row:

  1. Select any cell in the Table, go to the Table Design tab, and check the Total Row option.
Total Row option checked on the Table Design tab
  1. Click the Total Row cell under the Department column, click the drop-down arrow that appears, and select Count.
Table Total Row showing 6 under Department with the SUBTOTAL 103 formula Excel inserted

The Total Row now shows 6. If you click on that cell, you’ll see that Excel has inserted the formula =SUBTOTAL(103,[Department]) for you, where [Department] refers to the Department column of this Table.

Since this is SUBTOTAL with 103, the count changes as soon as you change the filter, and it also skips any rows you hide manually.

When you turn on the Total Row, Excel may also add a total under the last column on its own. If you don’t need it, click that cell and choose None from its drop-down.

Count Filtered Rows That Meet a Condition

Sometimes you don’t just want the number of filtered rows, but the number of filtered rows that meet a condition. For example, how many of the visible employees are in Chicago.

Below is the same employee list with the Finance rows filtered out, and I want to count the visible rows where the location is Chicago (the location I typed in cell C12), with the result in cell C14.

Filtered employee list with Chicago typed as the location to count and empty result cells

The first thing you may try is the COUNTIF function:

=COUNTIF(C2:C10,C12)
COUNTIF formula returning 4 because it also counts the Chicago rows that are filtered out

This gives us 4, but only 2 of the visible rows are in Chicago. COUNTIF counts every matching cell in the range, including the ones in rows that have been filtered out.

And SUBTOTAL can’t help on its own, as it respects the filter but doesn’t take a condition. So we need to combine the two ideas.

Here is the formula that counts only the visible rows where the location is Chicago:

=SUM((C2:C10=C12)*MAP(C2:C10,LAMBDA(c,SUBTOTAL(103,c))))
MAP and SUBTOTAL formula returning 2, the visible employees in Chicago

This gives us 2 (Nolan Scott and Ethan Matthews), which are the only visible employees in Chicago.

How this formula works:

  • (C2:C10=C12) – checks each location against Chicago and returns TRUE for a match and FALSE otherwise.
  • MAP(C2:C10,LAMBDA(c,SUBTOTAL(103,c))) – the MAP function hands SUBTOTAL one cell at a time. SUBTOTAL(103,c) returns 1 if that cell’s row is visible and 0 if it is hidden, so you get a list of 1s and 0s.
  • SUM(…) – multiplying the two lists gives 1 only for rows that are both visible and in Chicago, and SUM adds those 1s up.

The MAP and LAMBDA functions are available in Excel for Microsoft 365, Excel 2024, and Excel for the web.

If you are using Excel 2021 or an earlier version, use the below formula instead (in the example file, it’s in cell C15):

=SUMPRODUCT((C2:C10=C12)*SUBTOTAL(103,OFFSET(C2,ROW(C2:C10)-ROW(C2),0)))

This also gives 2. Here, the OFFSET function does the job MAP did in the earlier formula, by handing SUBTOTAL one cell at a time.

ROW(C2:C10)-ROW(C2) gives the list 0 to 8, and OFFSET moves down from C2 by each of those amounts. So SUBTOTAL gets C2, C3, and so on through C10, and returns 1 or 0 for each row, just like in the MAP version.

Pro Tip: OFFSET recalculates whenever anything in the workbook changes, which can slow down a big file. For large lists, enter =SUBTOTAL(103,C2) in cell D2, copy it down to D10, and then use =COUNTIFS(C2:C10,C12,D2:D10,1) instead.

Check the Count of Filtered Rows in the Status Bar

Not many Excel users know this, but the count of filtered rows is also shown in the status bar.

As soon as you apply a filter to your data set, you will notice that the status bar shows you how many records are visible after the filter from the total number of records.

Status bar showing 6 of 9 records found right after filtering out the Finance rows

Something like 6 of 9 records found – where 6 is the number of records visible after the filter has been applied and 9 is the total number of records in the data set.

Note that rows you hide by hand do not impact this. It only tells you how many records should be visible after the filtering, so if you manually hide any of the rows, that would still be counted.

You can also get this count by selecting the cells in any one column of your data, from the first data row to the last (a normal click-and-drag works, without the header).

Department cells of the filtered list selected with the status bar showing Count 6

The status bar now shows Count: 6. This Count only includes the visible cells in your selection, and it counts cells that aren’t empty, so pick a column with no blanks.

In this tutorial, I showed you how to use the SUBTOTAL function to count filtered rows in Excel. I covered the difference between the two arguments you can use in these SUBTOTAL functions.

And I have also covered the Total Row in Excel Tables, a formula to count filtered rows that meet a condition, and how to get the count of filtered rows through the status bar.

I hope you found this Excel tutorial useful.

Other Excel articles you may also like:

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

1 thought on “How to Count Filtered Rows in Excel?”

  1. Hi
    Can you tell me the formula for identifying a specific set of text within a set of data and its number of occurances excluding flitered data.
    Thanks

    Reply

Leave a Comment

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.