> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.omni.co/feedback

```json
{
  "path": "/modeling/dimensions/parameters/order-by-field",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# order_by_field

> Sets a field to be sorted by another field's values.

The order by field will be implicitly added to the query, but not shown in the result data unless explicitly included.

This parameter is often used when the main field is used to label buckets that put them in non-alphabetical order. For example, handling of `day_of_week` (orders by `day_of_week_number`) or `month` (orders by `month_of_year`).

This can be effective for sorting dynamically-grouped fields, such as `duration`.

Avoid specifying an `order_by_field` with more than one value for a given value of the dimension on which the `order_by_field` is defined. This can impact aggregations and seemingly create duplicate rows.

## Syntax

```yaml theme={null}
<dimension_name>:
  order_by_field: <field_reference>
```

## Properties

<ParamField path="dimension_name" type="object">
  The name of the dimension. Dimension names must:

  * Be unique within the view
  * Start with a letter
  * Contain only alphanumeric characters and underscores

  <Expandable title="dimension_name properties" defaultOpen="true">
    <ParamField path="order_by_field" type="string">
      An unquoted field reference specifying which field to use for sorting.
    </ParamField>
  </Expandable>
</ParamField>

## Examples

```yaml title="Custom sort order for bins" theme={null}
bin:
  order_by_field: bin_order
  sql: |
    CASE
      WHEN price > 100 THEN 'High'
      WHEN price > 20 THEN 'Medium'
      ELSE 'Low'
    END

bin_order:
  sql: |
    CASE
      WHEN price > 100 THEN 3
      WHEN price > 20 THEN 2
      ELSE 1
    END
```
