How to Apply UNIQUE by Specific Columns in Google Sheets

Google Sheets offers a highly versatile function, SORTN, that enables you to achieve what the UNIQUE function cannot: applying UNIQUE by specific columns. This means you can evaluate uniqueness for selected columns in a dataset instead of considering the entire row.

For instance, in a two-column dataset, you can apply UNIQUE by the first column (field) while retaining data in the second column. This level of flexibility makes SORTN an invaluable tool for advanced data manipulation.

When you use the UNIQUE function on a two-column dataset, it evaluates both columns together. This may not always yield the desired results. Using SORTN, however, you can customize the evaluation to focus on specific columns.

In this tutorial, I’ll show you step-by-step how to apply UNIQUE by specific columns using the SORTN function.

Why Use SORTN Instead of UNIQUE?

The UNIQUE function works well for simple datasets but has its limitations. It evaluates entire rows or columns, which makes it unsuitable when you need to focus on specific columns.

SORTN, on the other hand, provides greater flexibility. It allows you to apply UNIQUE by specific columns while also keeping the data sorted. Think of it as a “Group By” feature, but without aggregation.

Another key difference to note is that UNIQUE is case-sensitive, while SORTN is not. This distinction can be critical depending on your data needs.

Applying UNIQUE to One Column Using the UNIQUE Function

Let’s start with a simple dataset of fruit names in one column. Some fruit names appear multiple times.

Applying the UNIQUE function to a single column in Google Sheets

Using the formula:

=UNIQUE(A2:A10)

the UNIQUE function removes duplicates, leaving only distinct values.

Applying UNIQUE to One Column Using SORTN

With the SORTN function, you can achieve the same result as above but with additional features. Here’s the formula:

=SORTN(A2:A10, 9^9, 2, 1, TRUE)

This formula also removes duplicates, but the result is sorted by default.

Applying UNIQUE to one column using the SORTN function in Google Sheets

Key Elements in the SORTN Formula:

  • 9^9: A constant value required for Tie Mode 2.
  • 2 (Tie Mode 2): Activates advanced UNIQUE behavior.
  • 1 (Sort Column): Specifies the column to evaluate for uniqueness. Adjust this for specific columns. Note that you can use either the column index number or a range reference, such as A2:A10.
  • TRUE: Sorts in ascending order. Use FALSE for descending order.

Applying UNIQUE by Specific Columns in Two-Column Datasets

Using UNIQUE

In a two-column dataset (e.g., fruit names in column A and prices in column B), the UNIQUE function considers both columns together. For example:

=UNIQUE(A2:B11)

If the same fruit appears with different prices, each instance is treated as unique.

Applying UNIQUE to two columns using the UNIQUE function

Using SORTN

With SORTN, you can customize the evaluation:

UNIQUE by Both Columns:

=SORTN(A2:B11, 9^9, 2, 1, TRUE, 2, TRUE)

This formula evaluates both columns for uniqueness, similar to the UNIQUE function. Note that the result will be sorted.

In this formula, two sort columns are specified. The elements 1, TRUE, 2, TRUE after the tie-mode number define the columns to evaluate for uniqueness. As a result, the formula ensures both columns are considered when determining unique rows.

UNIQUE by Specific Column (First Column Only):

=SORTN(A2:A10, 9^9, 2, 1, TRUE)

This evaluates only the first column while retaining data from the second column.

Applying UNIQUE by specific columns in a two-column dataset using SORTN

Using SORTN to apply UNIQUE by specific fields is especially useful when working with grouped data or when you need to retain contextual information from other columns.

Applying UNIQUE by Specific Columns in Three-Column Datasets

For datasets with three columns, SORTN allows you to evaluate uniqueness based on any combination of columns.

For example, to apply UNIQUE by fields 1 and 3, use:

=SORTN(A2:C11, 9^9, 2, 1, TRUE, 3, TRUE)
Applying UNIQUE to three columns using the SORTN function

Conclusion

Learning how to apply UNIQUE by specific columns in Google Sheets can be a game-changer for data manipulation. Functions like SORTN provide unparalleled flexibility, surpassing the limitations of the UNIQUE function.

By mastering SORTN and understanding Tie Mode 2, you’ll unlock advanced techniques for working with complex datasets. However, keep in mind that UNIQUE is case-sensitive, whereas SORTN is not.

Explore this powerful function to elevate your Google Sheets skills to the next level!

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.

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...

Summarize Data and Keep the Last Record in Google Sheets

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

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...

1 COMMENT

  1. You really save the day man!! 🙂
    I used your example to construct a duplicates filter formula that works awesome 🙂

    Thank you very much!!!

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.