Calculation Issue in Forms
I've created a form with several areas where calculations are carried out. There are four sections, each containing different versions of the "Score" field, and these scores are averaged in a corresponding "Area Score" field located below each section.
The "Area Score" fields are calculating just fine with the following calculation:
var totalSum = 0;
var validFieldCount = 0;
var fieldNames = ["Score", "Score_2", "Score_3"];
for (var i = 0; i < fieldNames.length; i++) {
var field = this.getField(fieldNames[i]);
if (field != null) {
var fieldValue = field.valueAsString;
if (fieldValue !== "" && !isNaN(Number(fieldValue))) {
totalSum += Number(fieldValue);
validFieldCount++;
}
}
}
if (validFieldCount > 0) {
event.value = totalSum / validFieldCount /4;
} else {
event.value = ""; // Or 0, or "N/A", depending on desired behavior for no valid fields
}
I have a final section called "Evaluation Score," which is meant to be the average of all four "Area Scores." Initially, I used the built-in formula, "Value is the average of the following fields: Area Score, Area Score_2, Area Score_3, Area Score_4," but encountered issues because some entries use "N/A" instead of actual numbers. I tried several calculation methods for this section, but none worked correctly. What I need is a calculation that averages all four "Area Score" fields while ignoring any non-numeric values, since the standard formula doesn't handle non-numbers.
