Skip to main content
Participating Frequently
August 17, 2020
Question

Average ignore blanks but does not ignore 0s

  • August 17, 2020
  • 1 reply
  • 469 views

Looking for a Document level script and Field level script that will ignore blanks in the average but will count 0s in the average. I have several fields for subaverages and a cumulaitve average. I have been using these two scripts to ignore blanks but now they want the 0s in the averages. Any suggestions would help!

 

function calcAverage(fields, ignoreBlanks) {
var total = "";
var n = "";
for (var i in fields) {
var f = this.getField(fields[i]);
if (f==null) {
console.println("Error! Can't locate a field called: " + fields[i]);
continue;
}
if (f.valueAsString=="" && ignoreBlanks) continue;
total+=Number(f.valueAsString);
n++;
}
if (n=="") event.value = "";
else event.value = total/n;
}

 

calcAverage(["PLO_1_a", "PLO_1_b", "PLO_1_c", "PLO_1_d", "PLO_1_e"], true, true);

This topic has been closed for replies.

1 reply

Participating Frequently
August 17, 2020

Tried that and it's still not working. Any other suggestions?