Excel SORTBY Function: Syntax, Examples & Tips

The SORTBY function sorts data dynamically based on specified criteria and order preferences, allowing for flexible data organization.
Excel
=SORTBY(array, by_array1, [sort_order1], [by_array2], [sort_order2], ...)

One free generation or explanation per browser, shared across Excel and Google Sheets. Account usage limits apply afterward.

Need more than a single SORTBY formula? Try our free AI for Excel — it reads your entire spreadsheet, answers questions in plain English, and builds charts and analysis in the same chat.

On this page
  1. Parameters
  2. What is a SORTBY Formula in Excel?
  3. A Practical Example
  4. SORTBY Formula
  5. Result of the Formula
  6. Why Use SORTBY?
  7. Key Takeaways:
  8. Example use case

Parameters

array:
The range or array of values that you want to sort.

by_array1:
The range or array that determines the sort order of the array.

sort_order1:
An optional parameter that specifies the sort order for by_array1. Use 1 for ascending order and -1 for descending order. If omitted, the default is ascending order.

by_array2:
An optional range or array that can be used for a secondary sort order if there are ties in by_array1.

sort_order2:
An optional parameter that specifies the sort order for by_array2. Use 1 for ascending order and -1 for descending order. If omitted, the default is ascending order.

What is a SORTBY Formula in Excel?

The SORTBY function in Excel is a powerful tool that allows you to sort a range or array based on the values in one or more other ranges or arrays. It enables you to organize your data in a meaningful way, making it easier to analyze and interpret.

In simpler terms, the SORTBY function helps you rearrange your data based on specific criteria, allowing for a more structured view of your information.

A Practical Example

Imagine you are managing a student grades report, and you have the following data in an Excel spreadsheet:

Student Grades Table:

Student NameGradeAge
Alice8520
Bob9022
Charlie7821
David9223
Eve8820

You want to sort the students by their grades in descending order.

SORTBY Formula

To sort the student names based on their grades, you would use the SORTBY formula as follows:

Excel
=SORTBY(A2:A6, B2:B6, -1)

Breakdown of the Formula:

  • A2:A6: This is the range of values that you want to sort (student names).
  • B2:B6: This is the range that contains the values used for sorting (grades).
  • -1: This indicates that the sorting should be done in descending order (highest to lowest).

Result of the Formula

When you apply the formula, it sorts the student names based on their grades in descending order. The output would be:

Sorted Student Names
David
Bob
Eve
Alice
Charlie

Here, the students are listed from the highest grade (David with 92) to the lowest (Charlie with 78).

Why Use SORTBY?

The SORTBY function is particularly useful when you need to organize your data based on specific criteria without manually sorting it. It allows you to quickly rearrange your datasets, making it easier to draw insights and make informed decisions.

Key Takeaways:

  • SORTBY: Sorts a range or array based on the values in one or more other ranges or arrays.
  • Efficient Data Organization: Helps you quickly arrange data without complex sorting methods.
  • Common Use Cases: Ideal for organizing reports, analyzing scores, and any scenario where data needs to be sorted based on specific criteria.

Understanding how to use the SORTBY function can significantly enhance your data management capabilities in Excel, enabling you to present your datasets in a clear and structured manner.

Happy sorting!

Example use case

You have a table where Column A contains product names and Column B contains their corresponding sales figures. You can use the SORTBY function to sort the products based on their sales figures in descending order. This allows for quick identification of the top-selling products, enabling better inventory management and targeted marketing strategies without the need for complex sorting algorithms.

Beyond the SORTBY function: Better Analyst is a full Excel AI that goes well past individual formulas. Upload any spreadsheet and ask questions in plain English — you'll get formulas, data analysis, and charts back in seconds. It's a free AI Excel assistant that works with any .xlsx, .xls, or .csv file — no plugins, no Microsoft 365 required.

Don't have a spreadsheet yet? Use our free AI spreadsheet generator to turn a text prompt into a downloadable Excel file — a full AI Excel sheet maker that builds headers, columns, and formulas from your description.

Need more help with Excel formulas?

Create a free account for formula help, explanations, and spreadsheet analysis. Usage limits depend on your plan.

Explore all Excel formulas

Browse our complete library of Excel formula guides

Compare your options

Decide with evidence, not a sales pitch.

Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.

  1. 01ChatGPTOpen a balanced comparison prompt in ChatGPT.
  2. 02ClaudeOpen the same research prompt in Claude.
  3. 03PerplexityResearch the comparison with linked web sources.

AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.