home User Guide Getting Started Help Center Documentation Community Training Certification
menu
close
settings
Looker keyboard_arrow_down
language keyboard_arrow_down
English
Français
Deutsch
日本語
search
print
order_by_field

Usage

view: view_name {
  dimension: field_name {
    order_by_field: field_name
  }
}

Hierarchy

order_by_field

Possible Field Types

Dimension, Dimension Group, Measure

Accepts

A field name

Using order_by_field incorrectly can cause inconsistent, confusing behavior for users.

Definition

The order_by_field parameter enables you to use the sort order from a dimension, dimension group, or measure on another field of the same type, rather than using the default sort order. Fields referenced by the order_by_field parameter must match the field type of the parent field. That is, a dimension cannot reference a field of type: measure, and vice versa.

For example, you might have a table that contains both a status_id and a status_name column. When a user sorts by Status Name in the UI, you might want the names to appear in the order of the status ID, and not the alphabetical order of the names.

There should be a 1:1 relationship between a dimension or dimension group and the field referenced by the order_by_field parameter, so that the grouping characteristics of both fields are exactly the same. If you do not ensure this, sorting can appear to be random to users.

If there is one and only one status_id for each status_name, you could write:

dimension: status_name { sql: ${TABLE}.status_name ;; order_by_field: status_id }

With measures, order_by_field enables you to use the sort order from a measure on another measure. This can be helpful in cases where you want to sort a non-numeric measure type, such as list, by a numeric measure type.

In the below example, a list of cities is being ordered by a count measure:

measure: user_cities { type: list list_field: city order_by_field: count }

Top