# Text Facet (not alphabetical order)

**URL:** <https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186>\
**Category:** Support and Helpdesk\
**Created:** [January 15, 2024, 11:17pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186 "2024-01-15T23:17:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiolinus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/fabiolinus/32/350_2.png) [@fabiolinus](https://forum.openrefine.org/u/fabiolinus)\
**Post date:** [January 15, 2024, 11:17pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/1 "2024-01-15T23:17:46Z")

</div>

Hi. I need to create a text facet but not following alphabetical order. I'd like to see different item following the order they appear in its column. I created a second column IDX with an id number (1, 2, 3, ...) assigned to unique values. Thanks, Fabio

---

<div class="post-metadata">

**Author:** ![ostephens](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/ostephens/32/8_2.png) [@ostephens](https://forum.openrefine.org/u/ostephens)\
**Post date:** [January 17, 2024, 5:36pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/2 "2024-01-17T17:36:26Z")

</div>

Hi @fabiolinus could you give an example of what some simple data might look like and how you'd like that to appear in the facet? I haven't quite understood the result you are trying for at the moment

---

<div class="post-metadata">

**Author:** ![fabiolinus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/fabiolinus/32/350_2.png) [@fabiolinus](https://forum.openrefine.org/u/fabiolinus)\
**Post date:** [January 17, 2024, 6:37pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/3 "2024-01-17T18:37:33Z")

</div>

Hi Stephens. Thanks at all. I will try to explain me. This is your column: B, A, B, B, A, A, B. Only two distinct values: A and B. Text facet show you: A followed by B. No blank values are present.

This is your column: B, A, B, B, A, A, B. Only two distinct values: A and B. Customer Text facet shows you: B followed by A. No blank values are present. In order they appears, A follows B. Right?

Don't you?

---

<div class="post-metadata">

**Author:** ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)\
**Post date:** [January 29, 2024, 3:59pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/4 "2024-01-29T15:59:42Z")

</div>

Hi @fabiolinus :

B, A, B, B, A, A, B  
and  
B, A, B, B, A, A, B

seams to be the same data to me. What am I not understanding?

Regards,

---

<div class="post-metadata">

**Author:** ![fabiolinus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/fabiolinus/32/350_2.png) [@fabiolinus](https://forum.openrefine.org/u/fabiolinus)\
**Post date:** [January 29, 2024, 4:36pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/5 "2024-01-29T16:36:19Z")

</div>

Hi Antoine! Sorry for my bad example. I will try to explain me. Yes, they are the same because they are the same input for OR. That's it. But I am interested in the output (Text Facet). By default, Text Facet show me A like first item; then B like second item and so on (alphabetical order). But I am interested in a customized Text Facet.

B, A, B, B, A, A, B

In this example B cames before A because your unique values are B and A, ......... I'd like to have a customized Text Faced which shows B, A, ......Is this more clear? Thanks for your effort, Fabio

---

<div class="post-metadata">

**Author:** ![Antoine2711](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/antoine2711/32/85_2.png) [@Antoine2711](https://forum.openrefine.org/u/Antoine2711)\
**Post date:** [January 30, 2024, 6:19pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/6 "2024-01-30T18:19:22Z")

</div>

Hi @fabiolinus,

So, if I understand, you would like that the order of items in the Text Facet to appear in the same order they exists in the dataset?

Regards, Antoine

---

<div class="post-metadata">

**Author:** ![ostephens](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/ostephens/32/8_2.png) [@ostephens](https://forum.openrefine.org/u/ostephens)\
**Post date:** [January 31, 2024, 11:15pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/7 "2024-01-31T23:15:04Z")

</div>

If you want a (very hacky) way of doing this right now, you can sort of do it by creating a custom text facet with a "cross" expression

So if I have a project called "Alphabet" that contains one column "Letters"

| Letters |
| --- |
| B |
| A |
| B |
| B |
| A |
| A |
| B |
| D |
| C |

Then you can create a custom text facet on the letters column with and expression like:

value.cross("Alphabet","Letters")[0].index.toString("%04d")+" "+value

This will create a facet with values:

```plaintext
0000 B 4
0001 A 3
0007 D 1
0008 C 1

```

This is using the row.index from the first occurrence of the value in the column (found by the `cross` expression) with a bit of formatting to make sure "2" sorts before "10" etc.

Does that help?

---

<div class="post-metadata">

**Author:** ![fabiolinus](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/fabiolinus/32/350_2.png) [@fabiolinus](https://forum.openrefine.org/u/fabiolinus)\
**Post date:** [February 2, 2024, 2:11pm UTC](https://forum.openrefine.org/t/text-facet-not-alphabetical-order/1186/8 "2024-02-02T14:11:09Z")

</div>

Thanks a lot for your effort. This is a very good and practical solution for me. I didn't know the cross() command. I can think to change 0000, 0001, 0007 and 0008 to 01, 02, 03 and 04 for semplicity. But it is not so important at the moment. Thanks again, Fabio
