Find most recurring items in a database

I’m building an analytics page on my app. One of the analytics number I would like to show the user is show the most popular course being reserved by each of the customer.
For example
Customer 1 reserved class Math 10x
Customer 2 reserved class English 8 times
etc.

It’s possible that each customer reserved other classes other than just math. So he could have reserved English 9 times and physics 2 times, etc. but I want to show which class has been reserved hte most by each user.

I’m thinking of user the Search function in Bubble, but don’t know how to find the most popular item in the DB.

Anyone has an idea how to accomplish this?

Thanks in advance!

Do you have a Reservation data type with a relationship to the Class? If so, you can use a grouping expression. For example, in a repeating group’s data source:

Do a Search for Reservations :grouped by Class > add a “count” aggregation. Then, you can sort the list of groupings by the count so the highest count is the first in the list. Inside the cell, you can display the class name with “Current cell’s grouping’s class’s name”

If you’re just looking to display the top class only, then you can take that same expression (with sorting) and then add “first item”

You could also keep a count of reservations with a number field in the Class record as well. That will mean more frequent changes to data records every time a reservation is made/canceled, but a much simpler way of displaying the value.

Hope this helps!

Gaby
Coaching No Code Apps

1 Like

Thank you!

I also want to show the total money they did during a certain year and/or month.

For example if they choose from a dropdown 2025, I want the value to only sum the reservation total for 2025.
I added a dropdown for the year. I’m tryin to sum the reservation done only in the selected year, but I’m not able to get the correct expression to work.

In the DB, I have the created date (default bubble data type)

Any pointers?