> For the complete documentation index, see [llms.txt](https://docs.inforiver.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.inforiver.com/formula-syntax/math-functions/sort.md).

# SORT

Sorts a series of values in ascending order and returns them as an array for easy ranking and analysis.

The SORT function accepts a series of values and returns them as an array sorted in ascending order. It organizes the input numbers from the smallest to the largest, allowing individual elements to be accessed using their index positions. The function is useful for analyzing ranked data, identifying minimum or maximum values, and performing comparisons after ordering the dataset.

### Syntax

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

### Arguments

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

### 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&amp;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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
