UNIQUE Function in Visible Rows in Google Sheets

The UNIQUE function doesn’t inherently include only visible rows when it returns values, discarding duplicates in Google Sheets.

However, we can utilize a workaround method to achieve the desired result involving the MAP lambda function.

The logic is as follows: We will first identify visible rows and use the FILTER function to extract them. Then we apply the UNIQUE function to the extracted range.

Below, you will find step-by-step instructions for applying the UNIQUE function to visible rows in Google Sheets.

Sample Data and Testing Default Behavior of UNIQUE in a Filtered Range

The sample data is in A1:D16, where A1:D1 contains the field labels.

There are two unique categories in A2:A16, i.e., Electronics and Clothing, which we can extract using the following UNIQUE formula:

=UNIQUE(A2:A16)

Let’s filter out one of the categories, which is Electronics, and see what the formula returns.

For that, select A1:D16 and click Data > Create a Filter.

Sample Filtered Data in cells A1 to D16

Click the filter drop-down in cell A1, uncheck Electronics, and click OK.

Now, there is only one visible category, which is Clothing. However, the above UNIQUE formula will still return the same two unique categories.

The proper way to apply the UNIQUE function to visible rows in Google Sheets is here.

UNIQUE Function in Visible Rows in Google Sheets

Step-by-Step Instructions for Using the UNIQUE Function in Visible Rows

To determine whether cell A2 is visible in Google Sheets, you can use the following SUBTOTAL formula:

=SUBTOTAL(103, A2)

This formula outputs 0 if row #2 is hidden and 1 if it’s visible. Function #103 represents COUNTA in visible cells.

To apply this formula to each row in the range A2:A16, you need to convert it into a custom LAMBDA function.

The syntax for creating a custom lambda function is:

LAMBDA(name, formula_expression)

Here’s the custom lambda function:

LAMBDA(r, SUBTOTAL(103, r))

You can use this lambda function within the MAP function. The syntax for MAP is:

=MAP(array1, lambda)

Where array1 is A2:A16.

=MAP(A2:A16, LAMBDA(r, SUBTOTAL(103, r)))

In this lambda function, “r” represents the current element in the array. The MAP function iterates over each value in the array and returns 1 for visible rows and 0 for hidden rows.

Next, you can FILTER the range A2:A16 where the MAP output is 1. The syntax for FILTER is:

=FILTER(range, condition)

Here is that FILTER formula:

=FILTER(A2:A16, MAP(A2:A16, LAMBDA(r, SUBTOTAL(103, r))))

Here, the range is A2:A16, and the condition is the MAP formula.

Finally, wrap this formula with UNIQUE to get unique values in the visible rows:

=UNIQUE(FILTER(A2:A16, MAP(A2:A16, LAMBDA(r, SUBTOTAL(103, r)))))

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Excel: Highlighting Parent and Child Rows or Columns

When highlighting parent and child rows or columns, I mean applying conditional formatting to...

Excel: Filter Data with a Dropdown and ‘All’ Option (Dynamic Array)

You might know how to use the FILTER function to filter data based on...

Case-Sensitive Running Count in Google Sheets

This tutorial provides a solution for incorporating case sensitivity into the running count of...

Fix Fractional Percentage Formatting Issues in Google Sheets

Applying data validation is the only effective solution to resolve issues related to fractional...

More like this

Case-Sensitive Running Count in Google Sheets

This tutorial provides a solution for incorporating case sensitivity into the running count of...

Fix Fractional Percentage Formatting Issues in Google Sheets

Applying data validation is the only effective solution to resolve issues related to fractional...

Lookup the Smallest Value in a 2D Array in Google Sheets

We can use a combination of BYROW and SMALL with FILTER or XLOOKUP to...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.