Skip to main content
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

<dimension_name>:
  order_by_field: <field_reference>

Properties

dimension_name
object
The name of the dimension. Dimension names must:
  • Be unique within the view
  • Start with a letter
  • Contain only alphanumeric characters and underscores

Examples

Custom sort order for bins
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