# INDEXBY

INDEXBY( `column`, `integer`, `partition column`, `[sort column]` , `[ascending]`)

Indexes a given column when grouped by unique values within a `partition column`

{% hint style="info" %}
INDEXBY() is a [**window function**](https://docs.cascade.io/cascade/building-expressions/guide-to-window-functions), which performs like INDEX() except partitioned by the unique values of a different column.
{% endhint %}

### Arguments

| Argument             | Description                                                                                          |
| -------------------- | ---------------------------------------------------------------------------------------------------- |
| `column`             | Column to index                                                                                      |
| `integer`            | Index of indexed `column` to ouput                                                                   |
| `partition` `column` | Column containing unique values                                                                      |
| `[sort column]`      | Optional. Column with which to sort partitioned rows by. Defaults to index.                          |
| `[ascending]`        | Optional. Enter `True` to sort in ascending order (default), or `False` to sort in descending order. |

### Output

Outputs a given index from each partitioned group within the indexed `column`

### Examples

Let's say that we want to find the first state in each region in a table. We have a table that lists each state and its corresponding region -- by using `INDEXBY({State}, 1, {Region})` , we can select the first state for whatever region that state is in.

{% embed url="<https://datawrapper.dwcdn.net/LzfAE/1/>" %}


---

# 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.cascade.io/cascade/functions-and-expressions/functions/table/indexby.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.
