# Sort a repeating group on the nth element of a list variable

**URL:** <https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760>\
**Category:** Need help\
**Created:** [August 12, 2022, 5:57pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760 "2022-08-12T17:57:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nedmohr](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nedmohr](https://forum.bubble.io/u/nedmohr)\
**Post date:** [August 12, 2022, 5:57pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/1 "2022-08-12T17:57:35Z")

</div>

Hello all,  
I’m trying to sort a repeating group on the nth element of a list variable. List variables don’t seem to be available from the “sort by” box in the search dialogue. I tried using List Shifter, which at least lets me access list variables, but when I try to indicate which element to sort on, Bubble turns it red and tells me that the results is a single number rather than a list.  
 ![test](https://us1.discourse-cdn.com/bubble/original/3X/5/3/535416cfd9c0631fc1307aea29918c6b8789630a.png)

Any hacks appreciated. Bonus points if you can tell me the obvious thing that I’m missing. Thanks!

---

<div class="post-metadata">

**Author:** ![bubble.trouble](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@bubble.trouble](https://forum.bubble.io/u/bubble.trouble)\
**Post date:** [August 12, 2022, 6:19pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/2 "2022-08-12T18:19:18Z")

</div>

Filtering is different than sorting. The topic of the post and first sentence says filter but then you proceed into talking about sorting with a screen capture of sorting. Maybe it is clear to others but I’m presently uncertain if your question is in reference to filtering sorting or both.

---

<div class="post-metadata">

**Author:** ![nedmohr](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nedmohr](https://forum.bubble.io/u/nedmohr)\
**Post date:** [August 12, 2022, 8:46pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/3 "2022-08-12T20:46:42Z")

</div>

Ugh. That’s super embarrassing. I fixed the title to reflect my intent. Thanks!

---

<div class="post-metadata">

**Author:** ![bubble.trouble](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@bubble.trouble](https://forum.bubble.io/u/bubble.trouble)\
**Post date:** [August 12, 2022, 9:09pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/4 "2022-08-12T21:09:45Z")

</div>

I am not familiar enough with the ListShifter plugin (other then I know it’s a good plugin from a good author), but just using what Bubble provides, they offer a dynamic sort field. Keep in mind sorting is based on a field name in Bubble i.e sort Months by MonthNumber (where Months is a Data Type and MonthNumber is a field on the Months Data Type).

A dynamic sort field implies that the value you are providing is some field that exists on a DataType. It’s not completely clear to me based on the wording of your question if you are looking for this or something different.

Here is an example:

 ![Screenshot 2022-08-12 at 5.04.48 PM](https://us1.discourse-cdn.com/bubble/original/3X/1/9/19edc71658d5a1f7cb9e96bd634e275f79b632a8.png)

Data Types defined as follows:

 ![Screenshot 2022-08-12 at 5.08.55 PM](https://us1.discourse-cdn.com/bubble/original/3X/0/d/0d220a31820d1933a777419fcae0e56880e9b536.png)  
 ![Screenshot 2022-08-12 at 5.09.02 PM](https://us1.discourse-cdn.com/bubble/original/3X/2/9/292df88326f81e4218b94ea942cc940789cf40b0.png)

---

<div class="post-metadata">

**Author:** ![nedmohr](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nedmohr](https://forum.bubble.io/u/nedmohr)\
**Post date:** [August 15, 2022, 12:25pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/5 "2022-08-15T12:25:41Z")

</div>

I eventually solved this by passing a custom state to List Shifter. When creating a custom state you are able to make a list from the nth value from each list in a list of lists. I was then able to pass this custom state list to List Shifter, which then sorted the list.  
Hopefully this helps someone else.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [October 21, 2022, 5:58pm UTC](https://forum.bubble.io/t/sort-a-repeating-group-on-the-nth-element-of-a-list-variable/219760/6 "2022-10-21T17:58:08Z")

</div>

This topic was automatically closed after 70 days. New replies are no longer allowed.
