# How order\_by\_field parameter works?

**URL:** <https://community.omni.co/t/how-order-by-field-parameter-works/394>\
**Category:** Modeling\
**Tags:** modeling\
**Created:** [September 26, 2025, 7:47am UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394 "2025-09-26T07:47:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdrianaVela](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/adrianavela/32/341_2.png) [@AdrianaVela](https://community.omni.co/u/AdrianaVela)\
**Post date:** [September 26, 2025, 7:47am UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394/1 "2025-09-26T07:47:38Z")

</div>

Hello, Im using order\_by\_field parameter with colours parameter in a dimension. This dimension has age groups values (string) and I want to order by 18 - 25, 26 - 30, 31 -35… So I have created a new dimension using a case when statement to give an order for each age group value, so would look something like this:

`age_group_order:`  
`sql: CASE WHEN ${age_group} = ‘18-25’ THEN 1 WHEN ${age_group} = ‘26-30’ THEN 2`  
`WHEN ${age_group} = ‘31-35’ THEN 3 WHEN ${age_group} = ‘36-40’ THEN 4`  
`WHEN ${age_group} = ‘41-50’ THEN 5 ELSE 6 END`

The problem is when I use my age\_group dimension in a chart the values (18-25, 26-30…) do not respect that order even if the dimension has already de parameter order\_by\_field: age\_group\_order

Any suggestion here?

---

<div class="post-metadata">

**Author:** ![conor](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/conor/32/45_2.png) [@conor](https://community.omni.co/u/conor)\
**Post date:** [September 26, 2025, 12:40pm UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394/2 "2025-09-26T12:40:16Z")

</div>

Hi Adriana!

Could you share more details of the problem. I recreated your situation to test the sorting functionality. Here’s what I set up:

Created 5 buckets to bin ages into

```auto
  age_bin:
    sql: ${omni_dbt_ecomm__users.age}
    bin_boundaries: [13, 31, 50, 68, 87]
    label: Age Bins
    description: Age of the user
    order_by_field: age_bins_order

```

then but some custom sorting logic into another field called `age_bins_order` field like

```auto
  age_bins_order:
    sql: case when ${omni_dbt_ecomm__users.age_bin}='>= 13 and < 31' then 1 when
      ${omni_dbt_ecomm__users.age_bin}='>= 31 and < 50' then 2 when
      ${omni_dbt_ecomm__users.age_bin}='>= 50 and < 68' then 3 when
      ${omni_dbt_ecomm__users.age_bin}='>= 68 and < 87' then 4 when
      ${omni_dbt_ecomm__users.age_bin}='87 and above' then 0 end
    label: Age Bins Order

```

Then every time I sort the `age_bin` field in the results section of the tab, it gets ordered in either ascending order by the `age_bins_order` logic. You can see it in the below screenshot ( you do not need to include column B, I’m just doing it to show you the sort is being adhered to).

 ![Custom sort example](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/9b2a87d08c62c577b5f5f4e125dcb49cf5321564.png)

And the corresponding graph obeys the sort too.

 ![Screenshot 2025-09-26 at 13.37.44](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/07385dfa1072f707c5b1793df62c69c8b0496827.png)

Could you walk me through how your setup is configured? I want to make sure I’m not missing any nuances in your specific implementation. The key step is sorting in the results section.

---

<div class="post-metadata">

**Author:** ![AdrianaVela](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/adrianavela/32/341_2.png) [@AdrianaVela](https://community.omni.co/u/AdrianaVela)\
**Post date:** [September 26, 2025, 1:12pm UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394/3 "2025-09-26T13:12:48Z")

</div>

Hi Conor, thanks for your response!

Here are more details of my issue:

This is the definition of the dimension (screen shot below show values)

```yaml
age_group:
    sql: '"AGE_GROUP"'
    order_by_field: age_group_order
    colors:
      conditions:
        - condition:
            is: 50+
          color: "#EXXXXX"
        - condition:
            is: 18-25
          color: "#EXXXXX"
        - condition:
            is: 26-30
          color: "#XXXXX"
        - condition:
            is: 31-35
          color: "#XXXXX"
        - condition:
            is: 36-40
          color: "#XXXXX"
        - condition:
            is: 41-50
          color: "#XXXXX"
      else: "#XXXXX"

```

 ![image](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/de0330de45b668b6f2af87561d49775b9fda94a3.png)

And I have created a dimension to use in order\_by\_field. The definition is here:

```yaml
age_group_order:
 sql: 
     CASE WHEN ${age_group} = ‘18-25’ THEN 1 
          WHEN ${age_group} = ‘26-30’ THEN 2   
          WHEN ${age_group} = ‘31-35’ THEN 3
          WHEN ${age_group} = ‘36-40’ THEN 4 
          WHEN ${age_group} = ‘41-50’ THEN 5 
          ELSE 6 END
         format: number

```

If we use both of course it worked but then in the chart using, date field + age\_group + measure does not respect the order, the legend stay in this order by default.

 ![image](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/a419db1d6f1ec88dd4ab7e68ec080783616a3281.png)

---

<div class="post-metadata">

**Author:** ![AdrianaVela](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/adrianavela/32/341_2.png) [@AdrianaVela](https://community.omni.co/u/AdrianaVela)\
**Post date:** [September 26, 2025, 2:15pm UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394/4 "2025-09-26T14:15:47Z")

</div>

Hi Conor,

I found the reason, and it’s that I thought the order\_by\_field parameter automatically sorts the results without having to do order by on the results tab, but I understand that it is also necessary to sort them. Thanks for your feedback and for responding!

---

<div class="post-metadata">

**Author:** ![conor](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/conor/32/45_2.png) [@conor](https://community.omni.co/u/conor)\
**Post date:** [September 26, 2025, 4:05pm UTC](https://community.omni.co/t/how-order-by-field-parameter-works/394/5 "2025-09-26T16:05:57Z")

</div>

> [@conor](#):
>
> The key step is sorting in the results section.

Yep brilliant that you got sorted. Yes that’s the key step to initiate the sort be order selecting “Sort ascending/descending” or click on the header. Great that we got you sorted and thanks for using the community 🫲
