# SORT

The SORT function accepts a series of values and returns an array of the values sorted in ascending order.

## Syntax

```javascript
sort(value1,[value2]...)
```

## Arguments

value1,\[value2] – A series of numerical values to be sorted.

## Example

Consider that we are analyzing quarterly revenue. We need to determine the least but one revenue amount. In order to achieve this, we can use the sort function to sort the quarterly revenue for each row in ascending order. The sort function returns an array, we can access the elements using their index as shown in the image below.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FMvmDFd1bL3fVDt7bR5d2%2Fimage.png?alt=media&#x26;token=4cc4a9e5-5b9b-4f07-a79e-e31ea324653a" alt=""><figcaption><p>Application of SORT function</p></figcaption></figure>

In the example above, the variable 'a' holds the resulting array from the sort function. We can then access the least quarterly revenue element using the index a\[0] and the highest quarterly revenue using a\[3].

{% hint style="info" %}
To sort in descending order use the SORTDESC function.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inforiver.com/formula-syntax/math-functions/sort.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
