Efficient Data Sorting with SORT and SORTN Functions in Google Sheets

Sorting data effectively in Google Sheets can significantly enhance your ability to manage and analyze large datasets. This guide explores the SORT and SORTN functions, providing practical examples to help spreadsheet users, data analysts, and business professionals optimize their data organization workflows. 

i-radius

Whether you need to arrange data alphabetically, rank top-performing metrics, or apply advanced sorting techniques, this article will equip you with the tools and insights needed to streamline your process.

Overview of SORT and SORTN Functions

The SORT and SORTN functions in Google Sheets are essential tools for organizing and ranking data dynamically, allowing efficient analysis without altering the original dataset.

  • SORT: Arranges data in ascending or descending order based on one or more columns. It is ideal for tasks like alphabetically sorting product names, arranging revenue figures, or organizing dates. This function simplifies data organization, making it easier to identify trends and patterns.
  • SORTN: Extracts the top or bottom N rows from a dataset, with options for handling ties and sorting by multiple criteria. It’s useful for identifying top performers, highlighting the highest sales, or isolating the least profitable items. SORTN is perfect for ranking and analyzing subsets of data.

These functions are highly valuable for use cases such as managing inventory, analyzing performance metrics, and prioritizing tasks. By leveraging SORT and SORTN, users can streamline data workflows, gain insights, and easily make better decisions.

These tools offer a seamless way to organize, rank, and filter data, enhancing productivity and ensuring accurate data interpretation in Google Sheets.

Understanding SORT and SORTN Functions: Syntax and Examples 

The SORT and SORTN functions in Google Sheets provide dynamic ways to organize and rank data. While SORT arranges data based on specified columns, SORTN extracts top or bottom rows with advanced ranking options. These functions streamline workflows, making data analysis more efficient and actionable.

To effectively use the SORT and SORTN functions in Google Sheets, it's essential to understand their syntax and how each parameter influences results. Let’s break down their usage through concise examples highlighting their unique capabilities, such as sorting datasets by multiple criteria or extracting ranked rows with precision.

SORT 

The SORT function allows you to sort based on one or multiple columns, making it ideal for creating logical data arrangements.

Syntax of SORT

=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2], ...)

Let’s break down what these parameters represent:

  • range: The data range you want to sort.
  • sort_column: The column used as the sorting key, relative to the range.
  • is_ascending: Set to TRUE for ascending order or FALSE for descending order.
  • sort_column2, is_ascending2: [Optional] Additional columns and their sorting orders for layered sorting.

The function allows you to dynamically sort your data without altering the original order, making it an essential tool for organizing and analyzing large datasets in Google Sheets.

Example of SORT

Suppose you have an employee dataset and want to organize it by Joining Date in ascending order to identify the earliest joiners.

Syntax:

=SORT(B3:D10, 3, TRUE)
Example of Employee Dataset showing how the SORT function in Google Sheets arranges employee data by joining date in ascending order. i-border

Here:

  • B3:D10: Refers to the range of the dataset containing the employee information.
  • 3: Specifies that the data should be sorted based on the third column (Joining Date).
  • TRUE: Sorts the data in ascending order (earliest to latest).

The formula dynamically sorts the data based on the Joining Date, ensuring the earliest joiners are listed first.

SORTN

The SORTN function in Google Sheets is used to extract the top or bottom N rows from a dataset. It allows advanced ranking with options for handling ties and sorting by multiple criteria, making it ideal for filtering ranked subsets like top performers or bottom sales items.

Syntax of SORTN

=SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...)

Let’s break down what these parameters represent:

  • range: The data range from which rows are extracted.
  • n: [Optional] The number of rows to return (defaults to 1 if omitted).
  • Display_ties_mode [Optional]:  Determines how tied values are handled. 0 excludes tied rows exceeding the row limit. 1 includes all tied rows, even if it exceeds the limit. 2 removes duplicate rows.
  • sort_column1, is_ascending1 [Optional]: Specifies the first column for sorting and the sorting order (TRUE for ascending, FALSE for descending). Additional columns can be specified as needed.

The function is perfect for scenarios requiring ranked subsets, enabling efficient filtering and analysis in large datasets.

Example of SORTN

Suppose you have an employee dataset and want to find the top 3 employees who joined most recently (based on the Joining Date column).

Syntax:

=SORTN(B3:D10, 3, 0, 3, FALSE)
Using SORTN function in Google Sheets selects and displays the top rows based on value. i-border

Here:

  • B3:D10: Refers to the range of the dataset containing employee details.
  • 3: Specifies that the top 3 rows should be returned.
  • 0: Excludes tied rows exceeding the row limit.
  • 3: Sort the data based on the third column (Joining Date).
  • FALSE: Sorts in descending order to list the most recent joiners first.


This formula dynamically extracts the top 3 rows with the most recent joining dates, making it easy to focus on recent additions to the team.

Basic Examples of Using SORT and SORTN Functions in Google Sheets 

In this section, we’ll explore practical examples that demonstrate how to efficiently use these functions to sort data and extract top or bottom rows for better analysis.

Sort Data in Descending Order

When sorting data in descending order, the SORT function arranges values from highest to lowest. This is useful for highlighting the largest or most important entries first.

Suppose you have a list of names and want to sort them in reverse alphabetical order. 

To achieve this, you can use the following formula:

=SORT(B3:B10, 1, FALSE)
Example of using the SORT function in Google Sheets to organize data from highest to lowest. i-border

Here:

  • B3:C10: Specifies the range of the dataset to sort.
  • 1: Refers to the column used for sorting (in this case, the first column).
  • FALSE: Ensures the data is sorted in descending order.

Using this formula, the names will be arranged in reverse alphabetical order, making it easier to highlight or analyze the data based on descending priorities.

Sort Numerical Data in Ascending or Descending Order

Sorting numerical data by value using the SORT function is straightforward. You can arrange values in ascending order for more accessible analysis, or in descending order to highlight the highest scores first.

Suppose you have a dataset of performance scores and want to sort in ascending or descending order. We will see how to achieve both.

To achieve the ascending order, you can use the following formula:

=SORT(B3:C10, 2, TRUE)
Interface in Google Sheets showing how the SORT function is used to set the order of numbers. i-border

To achieve the descending order, you can use the following formula:

=SORT(B3:C10, 2, FALSE)
Using SORT function in Google Sheets to reorder numerical data from largest to smallest. i-border

Here:

  • 2: Specifies the second column (Performance Score) for sorting.
  • TRUE: Sorts the data in ascending order.
  • FALSE: Sorts the data in descending order.

Using these formulas, you can dynamically organize the performance scores to display either the lowest or highest values, depending on your needs. This is particularly helpful for performance reviews or ranking analysis.

Sort Data by a Range Reference Instead of Column Number

Sorting data by a range reference instead of a column number simplifies the sorting process by directly referencing the column to be sorted.

Suppose you have a dataset of performance scores and want to sort it by the "Performance Score" column in ascending order.

To achieve this, you can use the following formula:

=SORT(B3:C, C3:C, TRUE)
Sorting a dataset in Google Sheets with the SORT function using a cell range instead of a column index. i-border

Here:

  • B3:C10: Specifies the range of the dataset to sort.
  • C3: Directly references the "Performance Score" column to define the sorting order.
  • TRUE: Ensures the data is sorted in ascending order.

Using this formula, the dataset will be dynamically organized by performance scores in ascending order, making highlighting the lowest to highest scores easy without specifying a fixed column index.

Sort Data by Multiple Columns

Sorting data by multiple columns allows you to prioritize the organization of your dataset by applying layered sorting criteria.

Suppose you want to first sort by Department alphabetically (ascending) and then sort by Person Name alphabetically (ascending) within each department.

To achieve this, you can use the following formula:

=SORT(B3:C10, 2, TRUE, 1, TRUE)
SORT function in Google Sheets sorting data first by department, then by person name. i-border

Here:

  • B3: Specifies the range of the dataset to sort.
  • 2: Refers to the second column (Department) used as the primary sorting key.
  • TRUE: Sorts the Department column in ascending order.
  • 1: Refers to the first column (Person Name) used as the secondary sorting key.
  • TRUE: Sorts the Person Name column in ascending order.

Using this formula, the dataset will be organized first by department, and then names are sorted alphabetically within each department, providing a well-structured output.

Extract Top Values Including Ties Using SORTN in Google Sheets  

The SORTN function in Google Sheets allows you to extract the highest value from a dataset, including all tied values. This feature is useful for identifying top performers or results with multiple ties.

Suppose you want to extract the highest revenue target (%) from a dataset while including all tied values.

To achieve this, you can use the following formula:

=SORTN(C3:C10, 2, 1, 1, FALSE)
Using the SORTN function in Google Sheets to include tied values in the top-ranked results. i-border

Here:

  • C3:C10: Refers to the range containing the revenue targets.
  • 2: Specifies the number of unique rows to extract (2 rows in this case).
  • 1: Includes tied values for the top results.
  • 1, FALSE: Indicates sorting by the first column (in descending order).

This formula extracts all occurrences of the highest revenue target value (115), including ties, ensuring every instance of the top value is displayed in the results.

Find the Top 5 Representatives Using SORTN

The SORTN function can extract the top performers from a dataset based on specific criteria.

Suppose you have a dataset of employees and their performance scores and want to identify the top 5 performers for recognition.

To achieve this, you can use the following formula:

=SORTN(B3:C10, 5, 0, 2, FALSE)
SORTN function in Google Sheets displaying the top 5 sales representatives based on performance. i-border

Here:

  • B3:C10: Refers to the dataset containing names and performance scores.
  • 5: Specifies the number of rows to return (top 5 performers).
  • 0: Excludes tied rows that exceed the row limit.
  • 2: Refers to the second column (Performance Score) used as the sorting key.
  • FALSE: Sorts the scores in descending order (highest to lowest).

This formula dynamically ranks and returns the top 5 representatives based on their performance scores, making it easy to identify the highest achievers in the team.

Extract Bottom 5 Performing Products Using SORTN

The SORTN function can extract the lowest performers from a dataset based on specific criteria. In this case, we’ll find the bottom 5 representatives based on the number of projects completed.

Suppose you have a dataset of employees and their project completion counts, and you want to identify the bottom 5 performers to plan improvements or interventions.

To achieve this, you can use the following formula:

=SORTN(B3:C10, 5, 0, 2, TRUE)
Google Sheets using SORTN to find and show the lowest-performing five products. i-border

Here:

  • B3:C10: Refers to the dataset containing names and project completion counts.
  • 5: Specifies the number of rows to return (bottom 5 performers).
  • 0: Excludes tied rows that exceed the row limit.
  • 2: Refers to the second column (Projects Completed) used as the sorting key.
  • TRUE: Sorts the scores in ascending order (lowest to highest).

This formula dynamically ranks and returns the bottom 5 representatives based on their project completion counts, enabling you to identify the team members needing additional support quickly.

Advanced Techniques to Use SORT and SORTN Functions 

The SORT and SORTN functions in Google Sheets can transform your data handling. Advanced techniques allow you to organize datasets dynamically, extract top or bottom performers, or sort using multiple criteria. These functions empower you to analyze complex datasets effectively and make well-informed decisions efficiently.

Sort Data from Another Tab in Google Sheets

We can use the SORT function to organize data from a different tab in Google Sheets. This is particularly useful for cross-sheet analysis and reporting.

Suppose you want to sort data from another tab named Dataset based on the third column (Department) in ascending order.

To achieve this, you can use the following formula:

=SORT(Dataset!B3:E, 3, TRUE)

Here is the dataset in the tab which is named as “Dataset”:

SORT function in Google Sheets applied to a dataset located in a different sheet tab. i-border

The output is in the different sheet:

Example of using the SORT function in Google Sheets to pull and sort data from another tab. i-border

Here:

  • Dataset!B3:E: Refers to the data range in the "Demographics" tab.
  • 3: Indicates that the sorting is based on the third column (Department).
  • TRUE: Specifies ascending order for the sort.

This dynamically organizes data from a different tab, which is useful for cross-sheet analysis.

Sort Based on a Range Outside the Sort Range

The SORT function in Google Sheets allows you to sort values in one range based on the order of values in a whole separate range — a useful method when you want to organize data without disrupting the original dataset.

Let’s say you have a list of employees and their existing Employee IDs in column C, but you’ve been given a new list of New Employee IDs in column B. Instead of overwriting the existing values, you want to generate a new column in D that shows the Employee IDs sorted based on the names from column B in descending order.

To achieve this, you can use the following formula in cell D3:

=SORT(C3:C10, B3:B10, FALSE)
Using SORT function in Google Sheets to sort data based on values in a separate column range. i-border

Here:

  • C3:C10: This is the range of original Employee IDs that you want to sort.
  • B3:B10: This is the external sort range, containing the names that will dictate the sort order.
  • FALSE: This tells Google Sheets to sort the Employee IDs in descending order based on the values in column B.

As a result, you get the New Employee ID column in D, which shows the original IDs sorted according to the descending order of names in column B.

Important: Since column C (the range to be sorted) and column B (the sort criteria) are separate, it’s crucial not to delete either range — the formula depends on both being present.

This method is ideal when you want to sort a dataset based on an external list — like ranking IDs by new name order — without changing or reordering the rest of your table.

Sort Data by Multiple Columns with Multiple Conditions

The SORT function in Google Sheets lets you sort data using multiple columns with different conditions, allowing for complex data organization.

Suppose you want to sort a dataset by Projects Completed (Column 3) in ascending order and then by Person Name (Column 1) in descending order. 

To achieve this, you can use the following formula:

=SORT(B3:D10, 3, TRUE, 1, FALSE)
SORT function in Google Sheets sorting rows using more than one condition across several columns. i-border

Here:

  • B3:D10: Refers to the dataset containing the person's name, joining date, and number of projects completed.
  • 3, TRUE: Sorts the third column (Projects Completed) in ascending order.
  • 1, FALSE: Sorts the first column (Person Name) in descending order.

This formula organizes the dataset first by the number of projects completed, and for rows with the same number of projects, it sorts by the person’s name in descending order.

Extract Top 5 Rows Ignoring Ties and Specifying Sort Column with SORTN

The SORTN function in Google Sheets allows you to extract the top rows based on specific criteria while excluding ties. This is useful when creating unique rankings for detailed analysis and reporting.

Suppose you want to extract the top 5 rows based on Salary (Column 3) in descending order, excluding ties. 

To achieve this, you can use the following formula:

=SORTN(B3:D10, 5, 0, 3, FALSE)
SORTN function in Google Sheets extracting the top 5 rows, ignoring tied values, and sorting by a specific column. i-border

Here:

  • B3:D10: Refers to the dataset containing names, joining dates, and salaries.
  • 5: Specifies the number of rows to extract (top 5 rows).
  • 0: Excludes tied rows that exceed the row limit.
  • 3: Indicates the third column (Salary) used for sorting.
  • FALSE: Sorts the salary in descending order.

This ensures that only the top 5 unique rows based on salary are included in the output.

Include Tied Rows Using SORTN 

The SORTN function in Google Sheets allows you to include tied rows when extracting the top results. This ensures that all rows with the same rank are included in the output, even if it exceeds the specified limit.

Suppose you want to extract the top 4 rows based on Salary (Column 3) in descending order and include any tied rows. 

To achieve this, you can use the following formula:

=SORTN(B3:D10, 4, 1, 3, FALSE)
Google Sheets showing how the SORTN function includes all tied rows in the top results. i-border

Here:

  • B3:D10: Refers to the dataset containing names, joining dates, and salaries.
  • 4: Specifies the number of rows to extract (top 4 rows).
  • 1: Includes tied rows for the last rank within the limit.
  • 3: Indicates the third column (Salary) used for sorting.
  • FALSE: Sorts the salary in descending order.

This formula ensures all tied rows for the last rank are included in the output, providing an accurate ranking.

Remove Duplicates Using SORTN

The SORTN function allows you to sort data dynamically while removing duplicate rows. This is especially useful when working with large datasets where you must focus on unique values while sorting by a specific criterion.

Suppose you want to remove duplicate salary values from a dataset and display the top 5 unique salaries sorted in descending order.

To achieve this, use the following formula:

=SORTN(B3:D10, 5, 2, 3, FALSE)
Using the SORTN function in Google Sheets to remove duplicates and keep only unique rows. i-border

Here:

  • B3:D10: Refers to the range containing the dataset (Person Name, Joining Date, and Salary columns).
  • 5: Limits the result to the top 5 rows.
  • 2: Ensures duplicate rows are removed based on the sorting column.
  • 3: Indicates that sorting is based on the Salary column (third column in the range).
  • FALSE: Specifies descending order for sorting.

The top 5 unique salaries are displayed, removing duplicates and sorting in descending order. For example, duplicate salaries of, 50000 (Alice Johnson and Grace Lee) and, 55000 (Charlie Brown and Henry White) are resolved, keeping only the first occurrence for each.

💡 Learn how to simplify this process by following our step-by-step guide on how to remove duplicates in Google Sheets. This article will walk you through multiple methods to ensure your data remains accurate and organized.

Show Unique Rows and Duplicates with SORTN

The SORTN function helps sort and select rows based on specified criteria. By setting the third argument to 3, you can include both unique rows and their duplicates in the result. This is particularly useful when you want to analyze a dataset while preserving duplicate values.

Suppose you want to show the top 5 unique rows based on salary and include duplicates for those rows.

To achieve this, use the following formula:

=SORTN(B3:D10, 5, 3, 3, FALSE)
SORTN function in Google Sheets showing both unique entries and duplicates in a sorted list. i-border

Here:

  • B3:D10: Refers to the dataset range, including Person Name, Joining Date, and Salary.
  • 5: Limits the result to the top 5 rows.
  • 3(third argument): Includes duplicates for the top unique rows.
  • 3 (sort column): Indicates sorting is based on the Salary column (third column in the range).
  • FALSE: Sorts in descending order (highest salaries first).

Setting the third argument of SORTN to 3 retains duplicates for the top 5 unique salaries. For example, 55000 appears twice, showing both Charlie Brown and Henry White.

Sort and Extract the Top 5 Values by Date Using SORTN

The SORTN function in Google Sheets helps you extract the top 5 rows based on dates, sorted in descending order. This feature is ideal for identifying the most recent entries in a dataset, such as new hires or recent updates.

Let's extract the top 5 rows sorted by Joining Date, making it easy to focus on the most recent entries in your dataset.

To achieve this, use the following formula:

=SORTN(B3:D10, 5, 0, 2, FALSE)
SORTN function in Google Sheets sorting by date and selecting the top 5 most recent rows. i-border

Here:

  • B3:D10: Refers to the range containing the dataset (Employee Name, Joining Date, and Salary).
  • 5: Limits the result to the top 5 rows.
  • 0: Includes all rows without focusing on unique or duplicate entries.
  • 2: Sorts based on the second column (Joining Date).
  • FALSE: Displays the rows in descending order, showing the most recent dates first.

The formula extracts the top 5 rows by Joining Date, sorted in descending order, ensuring that the most recent dates are displayed first. This is a simple yet effective way to analyze datasets for chronological insights. 

Use Two Sort Columns to Extract Top 5 Rows Using SORTN

The SORTN function in Google Sheets enables advanced sorting by allowing you to specify multiple columns as criteria. By combining these columns, you can define primary and secondary priorities for your data.

Suppose we want to extract the top 5 rows sorted first by Joining Date in descending order (most recent first) and then by Salary in descending order to break any ties.

To achieve this, use the following formula:

=SORTN(B3:D10, 5, 0, 2, FALSE, 3, FALSE)
Google Sheets using SORTN to sort data by two columns and return the top 5 rows. i-border

Here:

  • B3:D10: Refers to the range containing the dataset (Employee Name, Joining Date, and Salary).
  • 5: Limits the output to the top 5 rows.
  • 0: Includes all rows without focusing on duplicates or unique rows.
  • 2: Specifies sorting based on the second column (Joining Date) as the primary criterion.
  • FALSE: Sorts the Joining Date column in descending order (most recent first).
  • 3: Adds the third column (Salary) as the secondary sorting criterion.
  • FALSE: Sorts the Salary column in descending order to prioritize higher salaries when dates are the same.

The formula sorts the dataset first by Joining Date to display the most recent entries, and then by Salary to prioritize higher earnings for rows with the same date.

Integrating SORT and SORTN with Other Google Sheets Functions

Combining SORT and SORTN with other Google Sheets functions allows you to perform advanced operations like filtering, removing duplicates, and querying data dynamically. Here are examples of how to integrate these functions for enhanced data manipulation.

Use SORT and FILTER Together for Multiple Conditions and Columns

The SORT and FILTER functions allow you to organize and filter data based on specific conditions dynamically. Combining these functions allows you to extract rows matching multiple criteria and sort them by one or more columns, providing a clean dataset for analysis.

Example 1: Using AND logic with SORT and FILTER

Suppose, we aim to identify employees from the Sales department whose salary exceeds 45000. Using AND logic, we’ll filter rows meeting both conditions and sort the results by Salary in ascending order and by Person Name as a secondary sort criterion.

To achieve this, use the following formula:

=SORT(FILTER(B3:D10, C3:C10="Sales", D3:D10>45000), 3, TRUE, 1, TRUE)
Combining SORT and FILTER functions in Google Sheets to organize data based on several criteria. i-border

Here:

  • B3:D10: Refers to the range containing the dataset (Person Name, Department, and Salary).
  • C3:C10="Sales": Filters rows where the department is Sales.
  • D3:D10>45000: Filters rows where the salary is greater than 45000.
  • 3: Specifies sorting based on the third column (Salary) as the primary criterion.
  • TRUE: Sorts the Salary column in ascending order.
  • 1: Adds the first column (Person Name) as the secondary sorting criterion.
  • TRUE: Sorts the Person Name column in ascending order to alphabetize names.

By combining SORT and FILTER with AND logic, we successfully extracted and sorted employees in the Sales department earning more than 45000.

Example 2: Using OR logic with SORT and FILTER

In this example, we aim to filter rows where either the department is "Sales" or the salary is greater than 55000. Using OR logic, we will extract all matching rows and sort them by Salary in ascending order, with a secondary sort by Person Name in alphabetical order.

To achieve this, use the following formula:

=SORT(FILTER(B3:D10, (C3:C10="Sales")+(D3:D10>55000)), 3, TRUE, 1, TRUE)
Another example of using SORT with FILTER in Google Sheets for multi-condition sorting. i-border

Here:

  • B3:D10: Refers to the range containing the dataset (Person Name, Department, and Salary).
  • (C3:C10="Sales"): Includes rows where the Department is "Sales."
  • +(D3:D10>55000): Adds rows where the Salary is greater than 55000 (OR logic).
  • 3, TRUE: Sorts the results by the Salary column (third column) in ascending order.
  • 1, TRUE: Adds a secondary sort by the Person Name column (first column) in ascending alphabetical order.

This formula filters rows that match either condition (Sales department or Salary > 55000) and sorts them by Salary first, then Person Name.

💡 Ever wondered how to extract meaningful data from large datasets effortlessly? The FILTER function in Google Sheets is your ultimate tool for dynamic filtering. Click here to read the full guide and elevate your data analysis skills.

Sort Horizontally Arranged Data Using SORT and TRANSPOSE in Google Sheets

When working with horizontally arranged data, the SORT function alone isn’t sufficient, as it’s designed for vertical data. To sort horizontally, you can use the TRANSPOSE function to temporarily rearrange the data vertically for sorting and then restore it to its original horizontal format.

Suppose the dataset contains employee IDs and their corresponding names arranged horizontally. We aim to sort the Employee IDs in ascending order and adjust the names accordingly while maintaining the horizontal layout.

To achieve this, use the following formula:

=TRANSPOSE(SORT(TRANSPOSE(C3:J4), 1, TRUE))
Using SORT and TRANSPOSE functions in Google Sheets to sort data that’s arranged in rows. i-border

Here:

  • C3:J4: Refers to the dataset range containing Employee IDs and Person Names.
  • TRANSPOSE: Temporarily converts the horizontal data into a vertical format so that the SORT function can process it.
  • SORT(TRANSPOSE(C3), 1, TRUE): 1 specifies that the sorting is based on the first column (Employee ID). TRUE sorts the data in ascending order.
  • TRANSPOSE(SORT(...)): Converts the sorted vertical data back into a horizontal format to match the original layout.

Using SORT and TRANSPOSE together allows you to sort horizontally arranged data without disrupting its structure. This method is especially useful for compact datasets or dashboards that require horizontal formatting.

Sort and Remove Duplicates Using SORT and UNIQUE Functions

The SORT and UNIQUE functions allow you to clean, organize, and analyze datasets by removing duplicates and arranging data in a logical order. Whether working with a single column or multiple columns, these functions simplify data processing.

Example 1: Sort data and remove duplicates from a single column

Suppose we want to extract unique salary values from the Salary column, remove duplicates, and sort them in ascending order. This helps create a clean and organized list of all distinct salaries.

To achieve this, use the following formula:

=SORT(UNIQUE(D3:D10), 1, TRUE)
Using SORT with UNIQUE in Google Sheets to arrange data and eliminate repeated rows. i-border

Here:

  • D3:D10: Refers to the range containing the Salary column.
  • UNIQUE(D3:D10): Identifies and removes duplicate salary values, leaving only distinct salaries.
  • 1, TRUE: Sorts the unique salary values in ascending numerical order.

This formula simplifies the dataset by removing duplicate salaries and sorting them. It provides a clear view of unique salary figures for easier analysis.

Example 2: Sort Data and Remove Duplicates from Multiple Columns

Now let's identify unique combinations of Department and Salary, remove duplicates, and sort the results by Department alphabetically and then by Salary numerically. 

To achieve this, use the following formula:

=SORT(UNIQUE(C3:D10), 1, TRUE, 2, TRUE)
Google Sheets example of cleaning and sorting data with the SORT and UNIQUE functions. i-border

Here:

  • C3:D10: Refers to the range containing the Department and Salary columns.
  • UNIQUE(C3:D10): Removes duplicate rows, ensuring that unique department-salary combinations are included.
  • 1, TRUE: Sorts the results by the first column (Department) alphabetically in ascending order.
  • 2, TRUE: Adds a secondary sort by the second column (Salary) in ascending numerical order.

Using this formula, we generated a dataset that shows unique department-salary combinations in a sorted format. It’s ideal for organizing data for analysis or reporting purposes.

Sort Data by Frequency of Occurrence Using SORT and COUNTIF

The combination of SORT and COUNTIF functions in Google Sheets allows you to organize data based on how often each value appears. This method is especially useful for analyzing trends, identifying the most common values, or understanding the distribution of your data.

In this example, we aim to sort the dataset based on how often each salary occurs (frequency) and, as a secondary sorting criterion, arrange salaries in ascending order within the same frequency. 

We'll first add a frequency column to help readers understand the frequency calculation.

In Column E (Frequency), use the following formula in E3:

=COUNTIF(C$3:C$10, C3)
SORT and COUNTIF functions in Google Sheets sorting data by how often each value appears. i-border

This calculates the number of occurrences of each salary in the Salary column (C3). Drag the formula down to fill the rest of the column.

Now, we’ll sort the dataset based on the frequency (descending order) and, for rows with the same frequency, by salary (ascending order).

Use the following formula:

=SORT(B3:C10, COUNTIF(C$3:C$10, C3:C10), FALSE, 2, TRUE)
Google Sheets showing data sorted by frequency using COUNTIF and SORT functions. i-border

Here:

  • B3:C10: Specifies the range of the dataset containing 'Employee Name' and 'Salary'.
  • COUNTIF(C$3:C$10, C3:C10): Calculates the frequency of each salary within the 'Salary' column. This generates an array indicating how many times each salary appears.
  • FALSE: Sorts the frequency array in descending order, so salaries that occur more frequently appear first.
  • 2, TRUE: Indicates that within the same frequency, the 'Salary' column (second column in the range) should be sorted in ascending order.

By combining COUNTIF and SORT, this formula allows you to dynamically organize data based on frequency and salary, ensuring a clear and structured output.

💡 Master data analysis in Google Sheets with the COUNTIF and COUNTIFS functions. This comprehensive guide by OWOX covers everything from filtering data to applying multiple conditions. Simplify your workflows and enhance your spreadsheet skills.

Using SORT and SORTN with QUERY in Google Sheets

Combining SORT and SORTN with QUERY in Google Sheets provides a powerful way to filter, organize, and analyze data dynamically. These functions allow you to sort datasets, apply conditions, and extract specific rows based on criteria, all within a single formula.

Example 1: Using SORT with QUERY

Suppose we aim to sort the dataset by salary in descending order and filter out rows where the salary is less or equal to 55000. The combination of SORT and QUERY functions achieves this dynamically.

Here is how we can achieve that:

=QUERY(SORT(B3:C10, 2, FALSE), "SELECT * WHERE Col2 >= 55000")
Example of using the SORT function inside a QUERY in Google Sheets to organize the results. i-border

Here:

  • B3:C10: Specifies the range of the dataset, including the Employee Name and Salary columns.
  • SORT(B3, 2, FALSE): Indicates the column used for sorting and Sorts the Salary column in descending order, placing the highest salaries at the top.
  • QUERY(..., "SELECT *): Selects all columns from the sorted dataset.
  • WHERE Col2 >= 55000: Filters the dataset to include only rows where the salary (Column 2) is greater than or equal to 55000.

This formula sorts the dataset in descending order by salary and dynamically filters out rows with salaries less than or equal to 55000. It’s an efficient way to combine sorting and filtering in a single formula.

Example 2: Using SORTN with QUERY

In many situations, you might have employees who record performance scores across multiple months. These scores reflect their contributions over time, and aggregating these scores can help you identify the top performers. 

For example, the same employee may have different performance scores for different months in a dataset. To rank employees by their total performance scores and determine the top three performers, we can use a combination of the QUERY and SORTN functions.

Here's how we can analyze the dataset:

=SORTN(QUERY(B2:D12, "SELECT B, SUM(C) WHERE B IS NOT NULL GROUP BY B ORDER BY SUM(C) DESC"), 3, 1)
SORTN combined with QUERY in Google Sheets to filter and rank data in one step. i-border

Here:

  • B2:D12 Specifies the dataset range, including the Employee Name, Performance Score, and Month.
  • SELECT B, SUM(C): Retrieves the Employee Name (Column B) and calculates the total performance score (SUM(C)) for each employee by summing their scores across all rows.
  • WHERE B IS NOT NULL: Ensures only rows with valid Employee Name values are included, excluding any empty names.
  • GROUP BY B: Groups the rows by Employee Name, ensuring that scores for the same employee are aggregated.
  • ORDER BY SUM(C) DESC: Sorts the employees in descending order of their total performance scores.
  • SORTN(..., 3, 1):
  • 3: Limits the output to the top 3 rows from the sorted result.
  • 1: Includes tied rows in the output if the 3rd ranked performer's total score is tied with others.

This formula dynamically aggregates performance scores and ranks employees to identify the top three performers. It’s a practical method for evaluating contributions across multiple periods and ensuring fair ranking, even in cases of ties.

Resolving Common Errors in SORT and SORTN Functions

Errors in SORT and SORTN functions can disrupt data organization and analysis. Understanding these errors and their solutions ensures smooth workflows, accurate sorting, and reliable insights, saving time and preventing frustration during data manipulation in Google Sheets.

#VALUE!

⚠️ Error: The #VALUE! error in SORT and SORTN arises when the range includes non-numeric values, blank cells, Boolean values (TRUE/FALSE), or error values. It can also occur if the input range is not continuous, disrupting the sorting process.

Solution: Ensure the range is continuous and contains only numeric or text data. Manually review the range to remove blank, Boolean, or error values. Alternatively, use the IFERROR function to replace errors with valid data, ensuring smooth sorting operations.

#N/A Error

⚠️ Error: The #N/A error in SORT occurs when the function cannot locate the value to sort. This may happen if the value is missing from the range or is of a data type that the SORT function cannot process.

Solution: Verify that the value exists in the range; if not, add it. For unsupported data types, convert them to sortable formats. For instance, transform dates into numeric values representing days for proper sorting.

#REF! Error

⚠️ Error: The #REF! error in SORT and SORTN occurs due to invalid range references, often caused by deleting or moving cells included in the function's range. Additionally, it may arise when the array result cannot expand because of data blocking the output cells.

Solution: Update the SORT or SORTN function to reflect the current range of your data. If the error is due to blocked cells, clear or move the blocking data to create space for the array output. This ensures the function works seamlessly.

Circular Reference Error

⚠️ Error: A circular reference error happens when the SORT function refers to the cell it’s in, creating a loop that Google Sheets cannot process. This disrupts the calculation and results in an error.

Solution: Ensure the SORT function does not include its own cell in the referenced range. Carefully review and adjust the range in your formula to eliminate any self-references, resolving the circular dependency.

Misinterpreting Sorting Criteria

⚠️ Error: Misinterpreting the sorting criteria in SORTN can lead to unexpected results. This occurs when the sort order or column index is misunderstood, such as using the wrong column for prioritization or incorrectly specifying ascending/descending order.

Solution: Double-check the sort order parameter (TRUE for ascending, FALSE for descending) and verify the column index matches your intended sorting logic. Clearly define your sorting priorities to ensure accurate results.

Incorrect range

⚠️ Error: An incorrect range in SORTN occurs when the specified range is incomplete, overlaps invalid data, or doesn’t include all necessary rows and columns for sorting. This can result in missing or inaccurate output.

Solution: Verify that the selected range is complete and free of errors. Ensure it covers all relevant data without including unnecessary or invalid cells. Adjust the range in the formula to match your dataset accurately.

Missing parameters

⚠️ Error: Missing parameters in SORT or SORTN, such as the sort_column, can cause unexpected results. Without this detail, Google Sheets cannot determine the sorting criteria, leading to incomplete or incorrect data arrangement.

Solution: Always specify the sort_column parameter in your formula. Double-check the syntax to ensure all required arguments are included, allowing the function to sort data as intended.

Best Practices for Optimizing Use of SORT and SORTN Functions

Using SORT and SORTN effectively requires an understanding of best practices to streamline data organization and reduce errors. Here are some tips to help you make the most of these functions.

Experiment with Different Sort Orders

Explore various sort orders with SORT and SORTN to organize data effectively. Sort data in ascending or descending order, and combine criteria to highlight trends or anomalies. Testing different arrangements ensures optimal clarity and insight from your datasets.

Combine with Other Functions for Advanced Sorting

Pair SORT and SORTN with functions like FILTER and, QUERY to create advanced workflows. For example, filtering a dataset before sorting allows you to focus on relevant data without manually adjusting the range.

Ensure Your Data Range is Correct

When using SORTN, verify that your data range is accurate and complete. An incorrect range can lead to missing or misleading results. Double-check your selection to include all relevant data for consistent and reliable sorting outcomes.

Double-Check the Limit Parameter

In SORTN, the limit parameter determines how many unique rows are returned. Double-check this value to ensure it matches your requirements. Setting it incorrectly might exclude essential data or return more results than needed, affecting analysis accuracy.

Add Secondary Sort Columns

With SORT, you can include secondary sort columns to refine your data arrangement further. Specify multiple criteria to organize data hierarchically, ensuring clarity when primary columns contain duplicate values. This technique enhances precision and readability in your sorted datasets.

Use "Sort Range" for Quick Access

For quick sorting without formulas, use the "Sort Range" option in Google Sheets. It allows you to sort a specific range of data by columns instantly. This is ideal for one-time sorting or quick adjustments during analysis.

Key Google Sheets Functions for Advanced Data Analysis

Unlock the full capabilities of Google Sheets with essential functions tailored for comprehensive data analysis. These versatile formulas simplify complex tasks, enabling you to work efficiently with large datasets, automate repetitive processes, and easily gain actionable insights.

  • VLOOKUP: Retrieve specific values by searching vertically within a range, making data retrieval faster and more accurate.
  • PIVOT: Summarize and visualize data effortlessly with pivot tables, uncovering trends and patterns.
  • IMPORTRANGE: Consolidate data from multiple Google Sheets into one, ensuring seamless integration of external sources.
  • MATCH: Locate the position of a value within a range, often used alongside INDEX for dynamic lookups.
  • COUNTA: Count non-empty cells to assess dataset size and completeness quickly.
  • ARRAYFORMULA: Apply formulas to entire ranges, automating calculations across multiple rows or columns.
  • HLOOKUP: Perform horizontal lookups to fetch values from rows in a specified range.
  • LOOKUP: Retrieve values flexibly by searching one range and returning corresponding values from another.

Uncover Insights with OWOX: Reports, Charts, and Pivots Extension

OWOX: Reports, Charts, and Pivots extension streamlines your data analysis process, offering powerful tools for creating detailed reports, interactive charts, and dynamic pivot tables in Google Sheets. Designed to minimize manual effort, this extension enables users to focus on uncovering valuable insights rather than wrestling with complex data.

By integrating seamlessly with your existing data sources, OWOX ensures that your reports and visualizations are always accurate and up-to-date. The intuitive interface simplifies customizing charts and pivot tables, allowing users of all skill levels to transform raw data into clear, actionable insights.

FAQ

You might also like

2,000 companies rely on us

Oops! Something went wrong while submitting the form...