SORT and SORTBY Functions

Excel provides powerful functions like SORT and SORTBY that allow users to organize data in their worksheets efficiently. These functions make it easy to arrange data in ascending or descending order based on one or more criteria. Understanding how to use SORT and SORTBY can significantly enhance your data management capabilities in Excel.

Syntax

The syntax for both SORT and SORTBY functions in Excel is as follows:

FunctionSyntax
SORT=SORT(array, [sort_index], [sort_order], [by_col])
SORTBY=SORTBY(array, by_array1, [sort_order1], [by_array2], [sort_order2], ...)

Example

Let's take a look at an example to see how these functions can be used effectively. Consider a table that lists sales data for different regions and sales representatives.

RegionSales RepSalesTarget
NorthAlice4500040000
EastBob4800045000
SouthCharlie4700047000
WestDavid4200043000

In this example, you could use the SORT function to sort the table by the "Sales" column in descending order. You could also use SORTBY to sort by "Region" and then by "Sales Rep."

Practice Exercise 1

Task: Sort the following table by the "Product Name" in ascending order and then by "Units Sold" in descending order.

Hint: Focus on sorting by "Product Name" first (alphabetical order), and then by "Units Sold" (numerical order). The SORTBY function will allow you to handle multiple criteria.

Practice Exercise 2

Task: Sort the following table by the "Department" in ascending order, then by "Employee Name" in alphabetical order, and finally by "Salary" in descending order.

Hint: You'll need to sort by "Department" first, then by "Employee Name," and finally by "Salary." Think about the order of sorting when applying the SORTBY function, and remember you can sort alphabetically and numerically at the same time.

Solution for Exercise 1:

To sort the table by "Product Name" in ascending order and then by "Units Sold" in descending order, you can use the SORTBY function as follows:

= SORTBY(A2:D5, B2:B5, 1, C2:C5, -1)

This formula sorts the data first by the "Product Name" (column B) in ascending order and then by the "Units Sold" (column C) in descending order.

Solution for Exercise 2:

To sort the table by "Department" in ascending order, then by "Employee Name" in alphabetical order, and finally by "Salary" in descending order, you can use the following SORTBY formula:

= SORTBY(A2:D5, C2:C5, 1, B2:B5, 1, D2:D5, -1)

This formula sorts the data first by the "Department" (column C) in ascending order, then by "Employee Name" (column B) in ascending order, and finally by "Salary" (column D) in descending order.