Excel SORT Function
The Excel SORT function returns the contents of a range or an array in ascending or descending order. The returned array is the same shape as the provided array argument.
In this section:
- Syntax of Excel SORT Function
- How to use Custom SORT in Excel?
- SORT by values.
- SORT by location.
- SORT by city and State.
- SORT States in Ascending and Sales in Descending Order.
1. Syntax:
=SORT(array,[sort_index],[sort_order],[by_col])
where:
array: The range or array users want to SORT.
[sort_index]: This is an optional argument and indicates a number of the row or column to be sorted.
[sort_order]: This is also an optional argument and indicates the desired sort order. For example, 1 for ascending order and -1 for descending order.
[by_col]: A logical value indicating the desired sort direction; FALSE to sort by row (default), TRUE to sort by column.
Notes:
- Where sort_index remains empty, Excel assumes the sort either by row1 or by column1.
- SORT Function sorts data in an array. To SORT data in the grid, users need to use SORTBY Function.
- An array may be the values in a row, or in a column, or a combination of both.
- SORT function returns an array and will spill it’s final results of a formula.
- Dynamic array does not work between workbooks.
Examples:
2. How to use Custom Sort in Excel:
To use the Excel built-in custom SORT, follow the steps below:
Step 1: Right-click on any cell (as 1 in image below).
Step 2: Click on Sort (2 as in image below).
Step 3: Click on Custom Sort (3 in image below)
After clicking on Custom Sort, you will see the Sort dialogue box (as in the image below). Now you can define sort by variable, and then by, and then by. To add additional then by, click “Add Level“.
Example: Suppose, we want to SORT by city and sales and the sales will be sorted from Largest to Smallest. Then click OK.
3. SORT by values:
Suppose, we want to SORT by sales. The formula is =SORT(C6:C17, 3, -1), which sorts the data by sales. Remember that 3 is the column reference, and -1 indicates descending order.
4. SORT by location:
Suppose, we want to SORT by city the sales by descending order. The formula is =SORT(C6:C17, 1, -1), which sorts the data by city and sales. Remember that 1 is the column reference, and -1 indicates descending order.
5. SORT by city and State:
Suppose, we want to SORT by City and States. The formula is =SORT(C6:C17,{1,2}), which sorts the data by City and States. Remember that 1 and 2 are is the column references, and empty sort_order will sort the values by ascending order.
6. SORT States in Ascending and Sales in Descending Order:
Suppose, we want to SORT by States in ascending and Sales revenues in descending order. The formula is =SORT(C6:C17,{2,3}, {1, -1}), which sorts the data by States in ascending and Sales revenue in descending order. Remember that the numbers {2, 3} within the first curly brackets are the column references and 1 and -1 indicate the order of sorting.
More related readings:
I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.