# Excel SORT function

## Summary

The Excel SORT function is used to sort the contents of a range or array either in ascending or descending order. It offers the flexibility to sort by multiple columns. SORT returns a dynamic array of results, which automatically updates if values in the source data change. This function is ideal for organizing data for analysis or presentation in a structured and orderly manner.
##### Syntax
```				```
=SORT(array, [sort_index], [sort_order], [by_col])
```
```
• array: The range or array to sort.
• [sort_index]: [Optional] The column index by which to sort. Default is 1 (the first column).
• [sort_order]: [Optional] Sort order: 1 for ascending (default), -1 for descending.
• [by_col]: [Optional] TRUE to sort by column, FALSE (default) to sort by row.
##### Return value
A sorted array based on the specified criteria.

## How to use

Use SORT by specifying the array or range you want to sort. Optionally, define which column to sort by (sort_index), the order of the sort (sort_order), and whether to sort by column or row (by_col).

## Examples

##### Simple SORT
Sorting a Range in Ascending Order: To sort a range by the first column in ascending order:
```				```
=SORT(A2:B10)
```
```
This formula sorts the range A2:B10 based on the values in the first column (column A) in ascending order.
##### SORT in Descending Order
Descending Order Sort by Specific Column: To sort a range by a specific column in descending order:
```				```
=SORT(A2:B10, 2, -1)
```
```
This sorts the range A2:B10 based on the values in the second column (column B) in descending order.
##### Horizontal SORT
Sorting Horizontally by a Specific Row: To sort a range horizontally based on values in a specific row:
```				```
=SORT(A1:E3, 1, 1, TRUE)
```
```
This formula sorts the range A1:E3 horizontally (by columns) based on the values in the first row.
##### SORT with Custom Sort Order
Custom Sort Order with Multiple Columns: To sort a range first by one column in ascending order and then by another column in descending order:
```				```
=SORT(A2:C10, {1, 2}, {1, -1})
```
```
This sorts the range A2:C10 first by column A in ascending order, then by column B in descending order.
##### SORT for Data Reorganization
Reorganizing Data with SORT: To sort data alphabetically and then by numerical value:
```				```
=SORT(A2:B10, {1, 2}, {1, 1})
```
```
This formula sorts the range A2:B10 first alphabetically based on column A and then numerically based on column B.