# THE SORTBY FUNCTION

Hello everybody,

There are functions about sorting among the newly released dynamic array functions. They are:

• SORT
• SORTBY

### WHAT DOES IT DO

With the SORTBY function that is one one the recently release dynamic array functions after Office 365, you can sort your table based on multiple columns/rows and sort order you want in a field without touching your table. Imagine suing the Sort feature we use a lot in Excel through the Custom Sort window. If we want to sort by multiple fields, we choose a column there and use one of the A to Z or Z to A options in the Order field and then choose the other field and choose the sorting order again. Thus, our table is sorted by the columns/rows and order we chose. Now we can do all this with one single function.

### SYNAX

=SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2],…)

There are 3 arguments in the function.
The first two are required, the others are optional.

Now let’s take a look at what these arguments mean, i.e. what the function wants from us and what we will give it.

 array Required The array or range to sort by_array1 Required The array or range to sort on [sort_order1] Optional The order to use for sorting. 1 for ascending, -1 for descending. Default is ascendi

### USE OF THE FUNCTION

• the data range to be listed in the array argument.
• the data range by which the sorting will be done based on which column/row first in the by_array1 argument.
• the sort order is chosen in the sort_order1 argument. If it is not stated, the A to Z order is accepted.
• you can continue by choosing a data range first and then sort order in the next optional array and orders.
• you have to state at least one column/row in the by_array1 argument.

Let’s give an example and see what happens when only the optional arguments are chosen.

Now, let’s make the sort_order argument -1 and thus sort by Z to A .

### SORT BY MULTIPLE FIELDS

We have sorted by one column and order so far. Now it is time to sort by multiple fields and orders. 😉 Let’s sort the Marka(Brand) field A to Z and then sort the Fiyat(Price) field Z to A and then change the sorting order of the Fiyat(Price) field and see the result.

### SORT FROM LEFT TO RIGHT IN A HORIZONTAL TABLE

If you wish, you can sort the data in the field you’ve stated as an array by the stated array or order from left to right in a horizontal table. The important thing is to state the array to be returned, field to be sorted and the sorting order. The table will be sorted by the criteria you stated, doesn’t matter if it is vertical or horizontal.

We will be talking about the other New Dynamic Array functions in our next articles.
And then we will be able to get things done way easier by using these new functions together. LONG LIVE THE NEW DYNAMIC ARRAY FUNCTIONS!

See you in other articles, bye. 🙋🏻‍♂️