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.

Marking Case-Sensitive Unique Values in Excel

Marking case-sensitive unique values provides several benefits compared to merely extracting them in an...

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

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.