How to Use the SORTBY Function in Excel
Welcome to our guide on using the SORTBY function in Microsoft Excel and Google Sheets.
Introduction
The SORTBY function enables sorting a range or array according to the values in a corresponding range or array. This is particularly useful for organizing data according to criteria specified in a different range.
Syntax
The syntax for the SORTBY function is consistent across Microsoft Excel and Google Sheets:
=SORTBY(range_to_sort, range_to_sort_by, [sort_order1], [range_to_sort_by2], [sort_order2], ...)
range_to_sort
: The range of cells you wish to organize.range_to_sort_by
: The range of cells that determines the order of therange_to_sort
.sort_order
: Optional. Use 1 for ascending order and -1 for descending order.
Examples
Sorting Student Scores in Excel/Sheets
Consider a dataset of student scores as shown below:
Student | Score |
---|---|
Tom | 85 |
Amy | 92 |
John | 78 |
Lisa | 88 |
To sort the students by their scores in ascending order, use the SORTBY function:
=SORTBY(A2:B5, B2:B5, 1)
This will return the students sorted by their scores:
Student | Score |
---|---|
John | 78 |
Tom | 85 |
Lisa | 88 |
Amy | 92 |
Sorting Data in Multiple Columns
For scenarios requiring sorting by multiple criteria, such as sorting by both age and name, you could apply SORTBY as follows:
=SORTBY(A2:B5, B2:B5, 1, A2:A5, -1)
Conclusion
The SORTBY function offers a robust mechanism for sorting data in Excel and Google Sheets based on secondary values. It is versatile in accommodating various sorting requirements and methodologies. Understanding and utilizing SORTBY facilitates effective data management and analysis in large data sets.
More information: https://support.microsoft.com/en-us/office/sortby-function-cd2d7a62-1b93-435c-b561-d6a35134f28f