Calculation aggregate .avg()

Hi guys, I am relatively new at coding with Velo.
I am trying to calculate the average value of all fields with ID #fieldOne of the current product in a dataset. I’m not sure if the calculation is already wrong, or I’m just having an error reading the result.
My text field “#textOutput” which should represent the average value, shows so currently only “[object Object]”.

I would be very grateful for any help.

async function avrgValue ( ) {
let filter = wixData . filter (). eq ( “productId” , product . _id );

wixData . aggregate ( “dataset” )
. filter ( filter ) //filter by the current product
. avg ( “fieldOne” ) //get average of all fields from fieldOne
. run ()
. then ( ( result ) => {
let avgFieldValues = result . items ;
$w ( “#textOutput” ). text = “” + avgFieldValues ; //put average value to textOutput
} )

Solved it by my own. Now it works:

let calcSoftware = await wixData . aggregate ( “ratings” ). filter ( filter )
. avg ( “software” , “softwareAvg” ). count (). run ()
let avgSoftware = calcSoftware . items [ 0 ]. softwareAvg ;
$w ( ‘#displayAvgSoftware’ ). text = “” + ( avgSoftware * 2 ). toFixed ( 1 );
$w ( ‘#barSoftware’ ). value = ( avgSoftware * 2 );
let totalSoftwareRatings = calcSoftware . items [ 0 ]. count ;
$w ( “#ratingCountsSoftware” ). text = “” + totalSoftwareRatings + " ratings" ;
if ( avgSoftware === null ) {
$w ( ‘#displayAvgSoftware’ ). text = “0.0” ;
$w ( “#ratingCountsSoftware” ). text = “0 ratings” ;
}

Hi @kristinateslanews

I am glad you figured out your problem.

Is there anyway you can help me please?

I already have average product rating on the product page using the wix example … I now need to reflect this on the product list repeater.

I have posted the details here.

thank you