Data store: How to sort values in a group and give them a rank based on the value in that group?

Hi all,

in a data store I want to sort values by group and give them a rank based on the value in that group.


My data store looks like this:

group = School_ID
Values = Videos watched

key School_ID Videos watched Rank
123456 5 10
654321 5 12
654123 7 14
321654 7 8
162534 5 7
615243 8 15

Example for group 5 (School_ID):

  • key 654321 would get a Rank of 1, as it got the highest value in that group (12)

  • key 123456 would get a Rank of 2, as it got the second highest value (10)

Example for group 7 (School_ID):

  • key 654123 would get a Rank of 1, as it got the highest value in that group (14)

I think you get the point. How do I archieve that?

Have you considered an array aggregator using the Group by feature in the module? This can be placed after the search on your data store which will retrieve multiple bundles for each row. The array aggregator can create groups by the school_ID key and then you can do a sort on the resulting bundles by the view count in descending order generating the rank order by each group.

3 Likes

Welcome to the Make community!

Every result (item/record) from a search module will output a bundle. To “combine” them into a single structure, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module.

Yes, that is possible. You’ll need four modules:

Setup

1. Get all records, sort by desc

2. Aggregate to array, group by school

3. Iterate each school’s array

4. Update each data store record

Select Bundle Order Position for the “Rank”, but this “Bundle Order Position” is by school because we are iterating the school’s array. So each school will begin the rank (Bundle Order Position) with 1.

Output

Give it a go and let us know if you have any issues!

3 Likes

Is it really this easy? Haven’t thought of using bundle order position. :man_facepalming: Thank you very much! :grinning: Sorry for the long wait for my answer but over the christmas days family and friends came first. :wink: All the best for you in 2024!

2 Likes

No problem, glad I could help!

Yes, Make is really easy and fun to use when you have learned all the basics!

If you want to learn more about Make, you can read up in the Help Center. I also recommend doing the tutorials in the Make Academy, and learn advanced skills like how to make custom apps to any API in the Make Partner Training Portal - both have certificates for successful completion.

Hope you had a wonderful holiday season, and see you around!

3 Likes