Excel Formula to Extract Unique Values From Filtered Rows

📅 Jun 18, 2026 📝 Sarah Miller

Managing large datasets in Excel often leads to frustration when trying to extract a clean list of unique records from rows that have been actively filtered. While standard Pivot Tables or basic UNIQUE formulas are common go-to methods, they fail because they evaluate hidden rows. Utilizing a dynamic array formula grants you automated, real-time updates that seamlessly ignore collapsed data. Under the stipulation that this requires Excel 365 and a visibility helper, combining UNIQUE, FILTER, and SUBTOTAL (using function 103) delivers the precise results you need. Below, we outline the exact formula syntax to implement this solution.

Excel Formula to Extract Unique Values From Filtered Rows

Excel is an incredibly powerful tool for data analysis, but one of its historical pain points has been working with filtered data. When you apply a filter to a dataset, you physically hide rows from view. However, standard Excel formulas-including newer dynamic array functions like UNIQUE-often ignore this filtered state and continue to evaluate the entire range, hidden rows included.

If you need to extract a list of unique values from a column, but only from the rows that are currently visible after filtering, you need a formula that can dynamically detect the "filtered status" of each row. In this comprehensive guide, we will explore how to build a robust Excel formula to index unique records based on filtered status, covering both modern Office 365 techniques and backwards-compatible solutions for older Excel versions.

The Core Challenge: Why Standard Formulas Fail

To understand why we need a specialized formula, consider how Excel handles filtered rows. When you filter a table to show only "North" region sales, the rows for "South," "East," and "West" are still present in your worksheet; their row heights are simply set to zero.

If you write a basic formula like =UNIQUE(B2:B20), Excel looks at the absolute cell coordinates in the array B2:B20. It does not check if those cells are visible to the user. Consequently, your unique list will contain sales reps from all regions, defeating the purpose of your active filter.

To solve this, we must introduce a function that is "filter-aware." In Excel, that function is SUBTOTAL (or its sibling, AGGREGATE).

The Magic of SUBTOTAL (Function_Num 103)

The SUBTOTAL function is uniquely designed to ignore hidden rows. By using the function code 103 (which corresponds to COUNTA while ignoring manually hidden and filtered-out rows), we can test whether a cell is visible.

  • If a row is visible, SUBTOTAL(103, Cell) returns 1.
  • If a row is hidden or filtered out, SUBTOTAL(103, Cell) returns 0.

By generating an array of 1s and 0s corresponding to the visibility of each row, we can create a logical mask to filter our dataset dynamically.

Method 1: The Modern Office 365 Approach (No Helper Columns)

If you are using Excel 365 or Excel 2021+, you have access to dynamic arrays (specifically FILTER, UNIQUE, and lambda helper functions like MAP or BYROW). This allows us to accomplish the task in a single, elegant cell formula without needing to clutter our sheet with helper columns.

The Formula

=UNIQUE(FILTER(A2:A20, (MAP(A2:A20, LAMBDA(row, SUBTOTAL(103, row))) = 1) * (A2:A20 <> "")))

How It Works Step-by-Step

  1. MAP(A2:A20, LAMBDA(row, SUBTOTAL(103, row))): The SUBTOTAL function normally expects a range and returns a single aggregated value. It cannot natively evaluate an array cell-by-cell. By nesting it inside the MAP function, we force Excel to evaluate SUBTOTAL(103, ...) individually for every single row in the range A2:A20. This outputs an array of 1s (visible) and 0s (hidden).
  2. ... = 1: We convert that array of 1s and 0s into a boolean array of TRUE and FALSE values, indicating which rows are currently visible.
  3. * (A2:A20 <> ""): This is an optional but highly recommended addition. It ensures that any blank cells in your range are evaluated as FALSE, preventing the formula from returning a 0 or blank space in your final unique list.
  4. FILTER(...): The FILTER function takes your original range (A2:A20) and extracts only the values where our visibility criteria evaluates to TRUE.
  5. UNIQUE(...): Finally, the UNIQUE function processes the filtered, visible-only list and strips out any duplicate records, spilling the unique values down the column.

Method 2: The Helper Column Approach (Highly Compatible)

If you are working on a massive dataset where lambda helper functions (like MAP) cause performance lag, or if you want a simpler setup that works across almost all modern versions of Excel, a helper column is the gold standard.

Step 1: Create the Visibility Helper Column

Insert a new column next to your data (let's assume Column C is your helper column, and your data starts on Row 2). In cell C2, enter the following formula and drag it down:

=SUBTOTAL(103, A2)

As you filter your main table, you will notice that the values in Column C dynamically switch between 1 (visible) and 0 (hidden).

Step 2: Write the Unique Filter Formula

Now, in the cell where you want your unique list to appear, write a simplified FILTER and UNIQUE formula that references your helper column:

=UNIQUE(FILTER(A2:A20, (C2:C20 = 1) * (A2:A20 <> ""), "No records found"))

This approach bypasses the complex MAP calculation, making your workbook recalculate significantly faster on large datasets containing tens of thousands of rows.

Method 3: The Legacy Excel Approach (Excel 2019 and Older)

If you or your users are running legacy versions of Excel that do not support dynamic array formulas (such as UNIQUE or FILTER), you can still achieve this result. However, it requires a helper column and a more complex array formula entered via Ctrl + Shift + Enter.

Step 1: The Helper Column

Just like in Method 2, create a helper column (Column C) with the formula:

=SUBTOTAL(103, A2)

Step 2: The Extract Formula

In your target cell (e.g., E2), enter the following array formula. If you are not on Office 365, you must press Ctrl + Shift + Enter to commit it:

=INDEX($A$2:$A$20, MATCH(0, COUNTIF($E$1:E1, $A$2:$A$20) + ($C$2:$C$20 <> 1), 0))

Drag this formula down. To prevent errors when the unique values run out, wrap the entire formula in IFERROR:

=IFERROR(INDEX($A$2:$A$20, MATCH(0, COUNTIF($E$1:E1, $A$2:$A$20) + ($C$2:$C$20 <> 1), 0)), "")

How the Legacy Formula Works

  • COUNTIF($E$1:E1, $A$2:$A$20): This builds a running count of values already extracted. If a value in our source data has already been indexed, this returns 1; otherwise, it returns 0.
  • + ($C$2:$C$20 <> 1): This adds a penalty to any hidden rows. If a row is hidden, its helper value is 0, so $C$2:$C$20 <> 1 evaluates to TRUE (which Excel treats as 1). This forces the sum to be greater than 0, preventing the MATCH function from selecting it.
  • MATCH(0, ..., 0): This looks for the first item that has a score of 0 (meaning it has not yet been extracted AND it is currently visible).
  • INDEX(...): This retrieves the actual text or numerical value from Column A based on the row index found by MATCH.

Practical Example & Use Case Scenario

Let's look at a practical example. Suppose we have the following sales table:

Row Region (Col A) Salesperson (Col B)
2NorthAlice
3SouthBob
4NorthCharlie
5NorthAlice
6SouthDave
7NorthCharlie

If we apply a standard Excel filter to show only the North region, rows 3 and 6 (containing Bob and Dave) will be hidden. Our visible rows are now Alice, Charlie, Alice, and Charlie.

Applying our Office 365 formula:

=UNIQUE(FILTER(B2:B7, MAP(B2:B7, LAMBDA(r, SUBTOTAL(103, r))) = 1))

The MAP segment evaluates the rows and determines that rows 3 and 6 are hidden, outputting {1; 0; 1; 1; 0; 1}. The FILTER function narrows the list down to Alice, Charlie, Alice, Charlie. Finally, UNIQUE processes this list and outputs:

  • Alice
  • Charlie

Important Troubleshooting Tips

When implementing these formulas in your real-world spreadsheets, keep the following considerations in mind:

  • Handling `#CALC!` Errors: In Method 1, if your filter criteria hides all data in the table, the FILTER function will find no matching records and throw a #CALC! error. You can easily handle this by utilizing the third argument of the FILTER function: =UNIQUE(FILTER(..., ..., "No Records")).
  • Recalculation Trigger: Excel formulas only recalculate when a cell value changes. Merely hiding or showing rows via a filter does not always automatically force Excel to recalculate formulas. If your unique list does not update immediately after changing a filter, press F9 to manually force a sheet recalculation.
  • Performance with Large Datasets: If your sheet contains more than 15,000–20,000 rows, the lambda-based MAP formula may cause brief freezes when altering filters. For large-scale data, always favor the Helper Column approach (Method 2), as it relies on highly optimized native recalculation paths.

Conclusion

By marrying Excel's powerful new dynamic array functions with the time-tested SUBTOTAL function, we can build highly responsive reports that respect user interactions. Whether you use the clean, single-cell Office 365 formula or the ultra-fast helper column approach, you can now seamlessly index unique records based entirely on their filtered status.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.