# Sort values by columns

=SORT(data,index,order,TRUE)

To sort values by columns, you can use the SORT function. In the example shown, data is sorted by the Group column. The formula in C8 is:

=SORT(C4:L5,2,-1,TRUE)

The result is the range C4:L5 sorted by score in descending order.

### How this formula works

The SORT function sorts a range using a given index, called *sort_index*. Normally, this index represents a column in the source data.

However, the SORT function has an optional argument called "*by_col*" which allows sorting values organized in columns. To sort by column, this argument must be set to TRUE, which tells the SORT function that *sort_index* represents a row.

In this case, we want to sort the data by Score, which appears in the second row, so we use a sort_index of 2. The SORT function that appears in C8 is configured like this:

=SORT(C4:L5,2,-1,TRUE)

*array*is the data in the range C4:L5*sort_index*is 2, since score is in the second row*sort_order*is -1, since we want to sort in descending order*by_col*is TRUE, since data is organized in columns

The SORT function returns the sorted array into the range C8:L9. This result is dynamic; if any scores in the source data change, the results will automatically update.

### With SORTBY

The SORTBY function can also be used to solve this problem. With SORTBY, the equivalent formula is:

=SORTBY(C4:L5,C5:L5,-1)

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.