Getting the mean of last 10 ratings in database?

Where do I find all the functions I can use in database or mathematically in general?

Every time someone gives a rating on one of my Locations, I want to get the mean of the last 10 bookings of that location (stored in Bookings) and store that back into the Location overall rating.

I think I can do this manually with various database queries and states but I’m wondering if there’s any handy functions I can use that will make such a task (ideally, much) easier?

1 - Grab the list of the last 10 ratings: There are several ways of doing it, but one way is doing a search for them, sort them by creation date and choosing the first 10.

2 - Then use the “group by” feature to group them and take the mean of them.

3 - Display that mean.

4 - ???

5 - Profit.

Thanks Vini

I’m wondering what I’m doing wrong here. First of all where does this list actually go? Second what is wrong with my logic? It seems to make sense but Bubble says nope.

Thanks for your help

I need to make a state to hold the list i believe

What does the issue checker says?

Turns out there’s an :average function which makes it all so much easier.

BUT, is there a way to have it just give average of the last X number of entries? I don’t see a way to specify the index number.

Before Average can you select the 10 items you want? Then apply average on that

I’m sorry I just don’t know how to do what you are saying, I’m a little new at this.

Try mixing with some of what you already did:

Search for Booking:items until #10’s ratings:average

See if this works. Or something that may look like that.

I just don’t know how to do the “until #10” part do you have a screenshot I could learn from?

Hey @ryan16,

My example in my app happens to be customers, but it’ll still be the same as what Vini mentions.


This topic was automatically closed after 70 days. New replies are no longer allowed.