# Grouping and sorting datas

**URL:** <https://community.glideapps.com/t/grouping-and-sorting-datas/82938>\
**Category:** Ask for Help\
**Created:** [July 4, 2025, 12:44pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938 "2025-07-04T12:44:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [July 4, 2025, 12:44pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/1 "2025-07-04T12:44:38Z")

</div>

Hi there,

I have a collection with musicians and I want to group them by Instrument in alphabetical order and sort each group by name in alphabetical order like this :

**Bass**

- A
- B
- C

**Drums**

- A
- B
- C

**Guitare**

- A
- B
- C

**Keyboards**

- A
- B
- C

**Vocals**

- A
- B
- C

I can do this with each instrument in a different collection but I can’t use the search bar option.

I know there are some tricks to do this but I didn’t understand the process 😅

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 5, 2025, 12:37am UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/2 "2025-07-05T00:37:43Z")

</div>

![CleanShot 2025-07-05 at 07.35.58@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/a/aa1395e3e909c9578ae78f2e7fd6b4b25772b614.jpeg)

Let’s say sample data is like this.

I have a sort column, which is a JS function.

```auto
function calculateValue(name, instrument) {
  return 10 * (instrument[0].toUpperCase().charCodeAt(0) - 64) + (name[0].toUpperCase().charCodeAt(0) - 64);
}

return calculateValue(p1, p2)

```

 ![CleanShot 2025-07-05 at 07.36.24@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/2/829fc2bb83eba48e5af6d479a189e63a7d09f8be.jpeg)

The function takes the first letter of the instrument and the name, converts them to their position in the alphabet (A=1, B=2, etc.), and then calculates a number that lets you sort your list first by instrument (alphabetically), and then by name within each instrument group. This way, when you sort by the result, your musicians are grouped and ordered just as you described.

 ![CleanShot 2025-07-05 at 07.37.04@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/f/ff96c2e96cd6d6613c43c6bfdcc4f1d61066674e.jpeg)

 ![CleanShot 2025-07-05 at 07.37.31@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/8/788773d04c42b19cf1fb60fc6889571bfc4873ca.jpeg)

---

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [July 7, 2025, 1:36pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/3 "2025-07-07T13:36:53Z")

</div>

Thanx for the reply

What am I doing wrong ? 🤔

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/3/c3363dd0da1fb53e554299bebaf4594713554503.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/e/fe229a7323c81fb6de1b2ca3f24d1f30d62099a6.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 7, 2025, 11:49pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/4 "2025-07-07T23:49:32Z")

</div>

![CleanShot 2025-07-08 at 06.47.47](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/d/fd95a7c6db0605407305adfdec170f46d2d589c3.jpeg)

Here’s an alternative approach.

 ![CleanShot 2025-07-08 at 06.48.02](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/2/52c6d30a2edd72c458070c340b75dd108c068aca.png)

 ![CleanShot 2025-07-08 at 06.48.10](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/d/1d6cba86bfe8417b2cbff23ba3b822f53470289a.png)

 ![CleanShot 2025-07-08 at 06.48.21](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/5/45d699867b4955aeb30c9ff152df93d2b42e8936.png)

 ![CleanShot 2025-07-08 at 06.49.13](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/9/599835da1e0cee951f9beb2ea4e48d8014ab53f4.png)

```auto
function calculateSortValue(instrumentsJoined, namesJoined, currentRow) {
  const [instrument, name] = currentRow.split('||').map(s => s.trim().toUpperCase());
  const instrumentList = Array.from(new Set(instrumentsJoined.split('||').map(s => s.trim().toUpperCase()))).sort();
  const nameList = Array.from(new Set(namesJoined.split('||').map(s => s.trim().toUpperCase()))).sort();
  const instrumentIndex = instrumentList.indexOf(instrument) + 1;
  const nameIndex = nameList.indexOf(name) + 1;
  return instrumentIndex * 1000 + nameIndex;
}

return calculateSortValue(p1, p2, p3)

```

---

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [July 8, 2025, 12:54pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/5 "2025-07-08T12:54:18Z")

</div>

Ho yeah, it works ! 🥳

Thanx a lot @ThinhDinh  
🙏

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 8, 2025, 11:58pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/6 "2025-07-08T23:58:03Z")

</div>

It wasn’t working correctly for your “Batterie” and “Basse” groupings as well, so I want to make sure it sorts instruments A-Z first, then names inside each group A-Z.

Happy to help!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [July 15, 2025, 11:58pm UTC](https://community.glideapps.com/t/grouping-and-sorting-datas/82938/7 "2025-07-15T23:58:03Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
