Office

Differences between SORT function and SORTBY function in Microsoft Excel

Microsoft Excel is a powerful tool for data analysis, and two of its key functions for sorting data are the SORT function and the SORTBY function. Understanding the differences between these two functions is crucial for anyone looking to optimize their data management in Excel. This article aims to clarify their unique features, syntax, and provide practical examples, making it easier for users to discern when to use each function.


Key Takeaways

  • SORT function: Sorts a range or array based on specified criteria.
  • SORTBY function: Sorts a range based on the values of one or more other ranges.
  • The choice between SORT and SORTBY depends on the context of your data and your specific sorting needs.

Purpose of Each Function

The SORT function is primarily used to organize data in a specific order, either ascending or descending. It can sort values based on one or more columns within the same range or array.

On the other hand, the SORTBY function enables you to sort a range or array by the values from one or more corresponding ranges or arrays. This function is useful when dealing with related datasets that need to be sorted based on different criteria.


Syntax and Arguments

SORT Function

The syntax for the SORT function is as follows:

SORT(array, [sort_index], [sort_order], [by_col])

  • array: The range or array to be sorted (required).
  • sort_index: The column number (or row number if sorting by rows) to sort by (optional; defaults to 1).
  • sort_order: Specifies the order of sorting (optional; 1 for ascending, -1 for descending; defaults to ascending).
  • by_col: A boolean value indicating whether to sort by rows or columns (optional; FALSE for sorting rows and TRUE for columns).
See also  Differences between LOOKUP function and HLOOKUP function in Microsoft Excel

SORTBY Function

The syntax for the SORTBY function is as follows:

SORTBY(array, sort_by_array1, [sort_by_array2], …)

  • array: The range or array to be sorted (required).
  • sort_by_array1: The range or array used for sorting (required).
  • sort_by_array2: Additional ranges or arrays used for sorting (optional; can include multiple sort criteria).

Key Differences

  1. Sorting Basis:

    • SORT sorts based on its own array.
    • SORTBY sorts based on another array.
  2. Sorting on Multiple Criteria:

    • SORT can only sort by the columns specified in its own dataset.
    • SORTBY can sort by multiple external arrays, providing more flexibility.
  3. Usability:

    • SORT is easier to use when you only need to sort based on the dataset.
    • SORTBY is beneficial when you need to sort based on related datasets.

Practical Examples

To illustrate how both functions work, consider the following small dataset of employees:

NameAgeSalary
Alice3060000
Bob2550000
Charlie3570000
Diana2880000

Using the SORT Function

If you want to sort this table by Salary, you can use the SORT function as follows:

excel
=SORT(A2:C5, 3, 1)

This function will output the following sorted table (by Salary, ascending):

NameAgeSalary
Bob2550000
Alice3060000
Diana2880000
Charlie3570000

Using the SORTBY Function

Now, if you want to sort this same table based on Age, you would use the SORTBY function like this:

excel
=SORTBY(A2:C5, B2:B5, 1)

This will give you the following output sorted by Age (ascending):

NameAgeSalary
Bob2550000
Diana2880000
Alice3060000
Charlie3570000
See also  Differences between TRUE function and FALSE function in Microsoft Excel

Conclusion

Both the SORT and SORTBY functions in Microsoft Excel offer valuable features for managing data effectively. The SORT function is straightforward and should be your go-to option when sorting a single array or range. Conversely, when you find yourself needing to sort a dataset based on external criteria or related values, the SORTBY function becomes the more powerful tool.

In summary, consider using SORT for simplicity and when sorting within the same dataset and SORTBY when dealing with multiple related criteria. Knowing how and when to use these functions will undoubtedly enhance your data manipulation skills in Excel.

About the author

Jeffrey Collins

Jeffrey Collins

Jeffery Collins is a Microsoft Office specialist with over 15 years of experience in teaching, training, and business consulting. He has guided thousands of students and professionals in mastering Office applications such as Excel, Word, PowerPoint, and Outlook. From advanced Excel functions and VBA automation to professional Word formatting, data-driven PowerPoint presentations, and efficient email management in Outlook, Jeffery is passionate about making Office tools practical and accessible. On Softwers, he shares step-by-step guides, troubleshooting tips, and expert insights to help users unlock the full potential of Microsoft Office.