# Customize your sort order of a text column in the table

**URL:** <https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659>\
**Category:** Tips and Showcases\
**Created:** [January 11, 2022, 8:30am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659 "2022-01-11T08:30:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khai\_To](https://community.holistics.io/user_avatar/community.holistics.io/khai_to/32/128_2.png) [@Khai\_To](https://community.holistics.io/u/Khai_To)\
**Post date:** [January 11, 2022, 8:30am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/1 "2022-01-11T08:30:32Z")

</div>

Currently, when sorting the column that has text (or string) data type, the order will be sorted alphabetically.

For example, you have the column with 3 distinct values: `high`, `medium`, `low`. If your sort descending, the order will be like below which is unexpected

| priority (desc) |
| --- |
| medium |
| low |
| high |

The correct order should be:

| priority (desc) |
| --- |
| high |
| medium |
| low |

Since the sort is not customizable, you could utilize our [business calculation](https://docs.holistics.io/docs/business-calculation) to transform your value into `1-low`, `2-medium`, `3-high` and apply the sort afterward

| priority (desc) |
| --- |
| 3-high |
| 2-medium |
| 1-low |

The sample syntax for transforming the column using business calculation could be

```plaintext
case(
  when: your_model.priority == 'High', then: '3-High',
  when: your_model.priority == 'Mid', then: '2-Mid',
  when: your_model.priority == 'Low', then: '1-Low',
  else: 'others'
) 

```

---

<div class="post-metadata">

**Author:** ![david-ri](https://community.holistics.io/user_avatar/community.holistics.io/david-ri/32/543_2.png) [@david-ri](https://community.holistics.io/u/david-ri)\
**Post date:** [January 12, 2022, 12:54am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/2 "2022-01-12T00:54:39Z")

</div>

This is a good tip, and we actually build the dimensions in the models to do this. But, what would be preferable would be being able to have a distinct sort order field.

Even better perhaps, having a sort key defined within the dimension definition, so it always orders correctly rather than users needing to know to use a separate sort field - a bit like what we already do in that case statement, but where the output is stored as a separate key pair.

---

<div class="post-metadata">

**Author:** ![Khai\_To](https://community.holistics.io/user_avatar/community.holistics.io/khai_to/32/128_2.png) [@Khai\_To](https://community.holistics.io/u/Khai_To)\
**Post date:** [January 12, 2022, 2:50am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/3 "2022-01-12T02:50:53Z")

</div>

> [@david-ri](#):
>
> Even better perhaps, having a sort key defined within the dimension definition, so it always orders correctly rather than users needing to know to use a separate sort field - a bit like what we already do in that case statement, but where the output is stored as a separate key pair.

That’s is a very good idea @david-ri, what I have imagined could be something like

```jsx
dimension priority {
    label: 'Priority'
    type: 'text'
    order_by: 'priority_index'
}

dimension priority_index {
    label: 'Priority Index'
    type: 'number'
    hidden: true
}

```

Of course, this is just an idea and we can actually make it better in the future. But feel free to drop any of your suggestions below

---

<div class="post-metadata">

**Author:** ![DataGeekDude](https://community.holistics.io/user_avatar/community.holistics.io/datageekdude/32/430_2.png) [@DataGeekDude](https://community.holistics.io/u/DataGeekDude)\
**Post date:** [January 14, 2022, 8:45am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/4 "2022-01-14T08:45:46Z")

</div>

I would also vote for this type of idea. We have a string field with \> 10 unique values. Using the above “workaround” does not work as the ordering is:  
1 - val1  
10 - val10  
11 - val11  
Which is obviously incorrect also.

Many other BI tools (Data Studio, PowerBI) already allow you to do this and I think it is a key feature that is required.

---

<div class="post-metadata">

**Author:** ![anthonytd](https://community.holistics.io/user_avatar/community.holistics.io/anthonytd/32/374_2.png) [@anthonytd](https://community.holistics.io/u/anthonytd)\
**Post date:** [January 14, 2022, 9:31am UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/5 "2022-01-14T09:31:45Z")

</div>

I guess we can do something like “01 - val1”, but yeah, the workaround is not scalable, the long-term solution is being voted and discussed here

> [@Order by Another Dimension](https://community2.holistics.io/t/order-by-another-dimension/634):
>
> It is frequently needed to order dimension elements other than alphabetically. To avoid having to concatenate a numeric field, it would be very useful to be able to specify an “Order By” dimension.

---

<div class="post-metadata">

**Author:** ![Cherice](https://community.holistics.io/user_avatar/community.holistics.io/cherice/32/1354_2.png) [@Cherice](https://community.holistics.io/u/Cherice)\
**Post date:** [February 15, 2024, 2:39pm UTC](https://community.holistics.io/t/customize-your-sort-order-of-a-text-column-in-the-table/659/6 "2024-02-15T14:39:50Z")

</div>

Hi, I appreciate this thread is from a while ago but custom sort is something we’ve been discussing in our team, is there anything on the roadmap for bringing in custom sorting?
