How to separate ratings outputs using a single database?

On my site I have multiple ratings input and output elements that are connected to a single database/dataset. I would like each ratings input to only affect the associated output, but the database seems to combine every input and give an average rating to every output. For example if i give 5 stars to ratingsinput1 and 3 stars to ratingsinput2, it displays an average of 4 stars to both ratingsoutput1 and ratingsoutput2. Is there a better way to specify which database item the ratings input must affect and which items it must pull from when calculating the ratings output? I am using the stock ratings system provided by wix detailed here .

function update_inputs(input, title) {
// query the current item from the dataset
.eq("title", title)
.then((results) => {
const currentItem = results.items[0]
// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.averageRating;
const count = currentItem.numberOfRatingsSub;
const total = currentItem.sumOfRatingSub;
// get the new rating from the ratings input
const newRating = $w(input).value;
// calculate the new average rating based on the current
//average and count
const newAverageLong = (total + newRating) / (count + 1);
// Round the average rating to 1 decimal point
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);
// set the dataset fields to the new average, total
// ratings, and number of ratings
'averageRating': newAverageShort,
'sumOfRatingSub': total + newRating,
'numberOfRatingsSub': (count + 1)
// save the dataset fields to the collection
.catch((err) => {
console.log('could not save new rating');
export function ratingsInput1_change(event) {
update_inputs('#ratingsInput1', "A Leaf in the Storm")

See the Review by User example which shows how to set up a Ratings system.

Thanks! I’ll check it out :slight_smile: