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

Usingorder_by_fieldincorrectly can cause inconsistent, confusing behavior for users.

Definition

Theorder_by_fieldparameter lets you use the sort order from a dimension, dimension group, or measure on another field of the same type, rather than using thedefault sort order.Fields that are referenced by theorder_by_fieldparameter must match the field type of the parent field. A dimension cannot reference a field oftype: measure,and vice versa.

For example, you have a table that contains both astatus_idand astatus_namecolumn. When a user sorts byStatus Namein the UI, you want the names to appear in the order of the status ID, and not the Alpha betical order of the names.

There should be a 1:1 relationship between a dimension or dimension group and the field referenced by theorder_by_fieldparameter, 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 onestatus_idfor eachstatus_name,you could write:

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

With measures,order_by_fieldlets you 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 astring,by a numeric measure type.

In this example, a string of cities is ordered by acountmeasure:

measure: user_cities {
type: string
order_by_field: count
}