Forum Academy Marketplace Showcase Pricing Features

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)?

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.

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