Calculate average with N/A
Copy link to clipboard
Copied
I am trying to average the sum of the boxes shown below with the formula I pasted and it is not working. I am also wanting to include that if a field has N/A it would not affect the score. Any help would be appreciated.
Copy link to clipboard
Copied
Change first field from "Score" to "Score0" and try this:
var sum = 0;
var n = 0;
for(var i=0; i<=24; i++){
if(typeof this.getField("Score"+i).value == "number"){
n++;
sum += Number(this.getField("Score"+i).valueAsString);}}
if(n != 0)
event.value = sum/n;
else
event.value = "";
It's easier to help you if you post full script in text format instead of photo.
Copy link to clipboard
Copied
I tried changing those values and it's weird nothing calculates as shown below. It doesnt come up with errors or anything.
Also here is the full script sorry about that:
function myAverageFunction(aNames) {
var sum = 0;
var n = 0;
for(var i=0; i<=24; i++){
if(typeof this.getField("Score"+i).value == "number"){
n++;
sum += Number(this.getField("Score"+i).valueAsString);}}
if(n != 0)
event.value = sum/n;
else
event.value = "";
}
event.value = myAverageFunction(["Score0", "Score1", "Score2", "Score3", "Score4", "Score5", "Score6", "Score7","Score8","Score9","Score10","Score11","Score12","Score13","Score14","Score15","Score16","Score17","Score18","Score19","Score20","Score21","Score22","Score23","Score24"]);
Copy link to clipboard
Copied
Use only the script I gave you.
Copy link to clipboard
Copied
Nevermind that worked you are amazing thank you so much.

