Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculate average with N/A

New Here ,
Apr 11, 2023 Apr 11, 2023

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.

 

Carolyn5FDC_0-1681236395588.pngexpand image

 

TOPICS
Edit and convert PDFs , JavaScript
635
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2023 Apr 11, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 11, 2023 Apr 11, 2023

I tried changing those values and it's weird nothing calculates as shown below. It doesnt come up with errors or anything.

 

Carolyn5FDC_0-1681241919099.pngexpand image

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"]);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2023 Apr 11, 2023

Use only the script I gave you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 11, 2023 Apr 11, 2023
LATEST

Nevermind that worked you are amazing thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines