Display the most common item of a repeating group

I have a repeating group list and would like to have a text field outside of the repeating group reference the most common item in the list.

For example, here is my list of things:

TIME OF DAY
Morning
Afternoon
Afternoon
Night
Morning
Early Morning
Night
Afternoon

I want to search this list and display Afternoon since it is the most common word in the list.

Is this possible?

Within Bubbleā€™s native functions, Iā€™m not so sure. Hereā€™s a suggestion though; look into exporting that list with Blockspring and finding the most common item there. I havenā€™t fully explored Blockspring, so this may not be viable. Depending on your use case, it may or may not be practical solution.

Blockspring would certainly help you with this, since you can code anything yourself there. Natively, thatā€™s a new sorting which we donā€™t support yet. Iā€™ll put that on our list (but canā€™t say when weā€™ll be able to do this though).

It is tricky. You can certainly pull out a ā€œrankingā€ by counting the number occurrences (assuming they are on the database). But you canā€™t then either pull that out externally of the repeating group or sort on it. You can almost get their with the dynamic sort field, but it wonā€™t let you access the row to do the search : count to sort on it (as that would be a double pass I guess).

Other than blockspring, you could look at maybe doing a database update with your counts on page load and then pulling that back, sorted, with :firstitem.

Hey Nigel & @emmanuel

How do you pull out a ā€œrankingā€ by counting the number of occurrences (assuming there is a list of things in the database)?

1 Like

In your repeating group you can do a search for each item in the row and then pull back :count

So that gives you unsorted ā€œrankingā€. Sorting on this derived number is the tricky bit.

@jay how did you end up solving this?

@twr2105 Unfortunately, I havenā€™t solved this yet. Exploring how to send bubble database data to blockspring, calculate and display results back in bubble.

1 Like

I was thinking about a delayed workflow that updated the ā€œrankā€ periodically, but I donā€™t think that will work either as you can run it for everything I donā€™t think.

Does anyone know if this problem with sorting on a dynamic field which has been specially calculated for the repeating group cell has been solved? Almost seems that we need to sort the repeating group post having recieved uts source dataā€¦

Any news on this one?

I was able to solve this to list the most popular Genres on my app. This also eliminates any Genres that havenā€™t been applied to a song yet. Hereā€™s a screenshot of what I did:

Hi, I know itā€™s a very old post but I donā€™t really get this solutionā€¦

I get this error in the debugger: The dynamic sort field ā€˜xxxā€™ is not recognized as a field on the type Song

Does anyone managed to solve this?

Thanks,
Carlo

1 Like

You can do this in a text element by following these steps:

  1. Do a search for the thing or get a list of things from a repeating group.

  2. Group it by the field youā€™re interested in displaying, and add a ā€œCountā€ aggregation:

  3. Sort by ā€œcountā€:

  4. :First item

3 Likes