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
Theorder_by_field
parameter 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_field
parameter 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_id
and astatus_name
column. 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 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 onestatus_id
for eachstatus_name
,you could write:
dimension: status_name {
sql: ${TABLE}.status_name;;
order_by_field: status_id
}
With measures,order_by_field
lets 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 acount
measure:
measure: user_cities {
type: string
order_by_field: count
}