Calculations with Dataset Entries

Hey all!
I am trying to calculate an average of one field of each row of my dataset. The dataset gets filtered in another functiona according to user input
My function to do the calculations looks as follows:

async function queryImpact(){
 const results = await $w('#dataset2').getItems();
 let len = results.totalCount;
 let sumScore = 0;
 for (let i=0;i<len;i++){
        sumScore += results.items[i].overallScore;
    }
    Impact= sumScore/len;
    $w('#txtTestEndNumber').text=Impact.toString();
}

I call the function after a Button Click:

export async function btnReady_click(event) { 
    queryImpact();
}

For some reason, in the txtTestEndNumber I get always NaN after I click the Button…
I am quite new to JS so I could use some help!

Instead of:

queryImpact();

try this:

await queryImpact();

Thank you for your answer! I tried this but unfortunately it still writes NaN to my textbox… any ideas why, or maybe ideas how I could try it in another way?

Edit: It also sometimes gets stuck and doesn’t do anything…

Try a console.log for sumScore and .overallScore after:

sumScore += results.items[i].overallScore

Maybe the error is there.