# SORT

### Description

Sorts the entries of the given parameter in ascending order.

### SORT(Scalar\<any>)

```java
SORT(scalar: Scalar<any>): Scalar<any>
```

Sort the entries of the given Scalar\<any> in ascending order.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>scalar</td><td>A scalar of type any</td></tr></tbody></table>

#### Returns

Returns the given scalar sorted in ascending order as type Scalar\<any>.

***

### SORT(Vector\<any>)

```java
SORT(vector: Vector<any>): Vector<any>
```

Sort the entries of the given Vector\<any> in ascending order.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>vector</td><td>A vector of type any</td></tr></tbody></table>

#### Returns

Returns the given vector sorted in ascending order as type Vector\<any>.

***

### SORT(GroupedScalar\<any, any> \[, Scalar\<Text>])

```java
SORT(group: GroupedScalar<any, any> [, by: Scalar<Text>]): GroupedScalar<any, any>
```

Sort the entries of the given GroupedScalar\<any, any> in ascending order by values.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>group</td><td>A GroupedScalar of type &#x3C;any, any></td></tr><tr><td>by</td><td><p>The by parameter is optional.</p><p></p><p>Specifies by which attribute of the vector it should be sorted.Allowed values are <em>byGroupKey</em> and <em>byGroupValue</em>. </p><p></p><p>Default is byGroupValue.</p></td></tr></tbody></table>

#### Returns

Returns the given group sorted by the specified property in ascending order as type GroupedScalar\<any, any>.

***

### SORT(GroupedVector\<any, any> \[, Scalar\<Text>])

```java
SORT(group: GroupedVector<any, any> [, by: Scalar<Text>]): GroupedVector<any, any>
```

Sort the entries of the given GroupedVector\<any, any> in ascending order by values.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>group</td><td>A GroupedVector of type &#x3C;any, any></td></tr><tr><td>by</td><td><p>The by parameter is optional.</p><p></p><p>Specifies by which attribute of the vector it should be sorted.Allowed values are <em>byGroupKey</em> and <em>byGroupValue</em>. </p><p></p><p>Default is byGroupKey.</p><p></p><p>If sorting by value, then it does this by comparing the number of values.</p></td></tr></tbody></table>

#### Returns

Returns the given group sorted by the specified property in ascending order as type GroupedScalar\<any, any>.

### Examples

Sort GridPowerConsumption in ascending order.

```java
SORT($GridPowerConsumption)
```

Sort GroupedByDevicePowerConsumption in ascending order by event

```java
SORT($GroupedByDevicePowerConsumption, byGroupKey)
```


---

# 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://doc.moost.io/platform-manual/rules/rule-language/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.
