Hello all,
This was found to be a bug (SCR 172338) where it looks like both the "IfTrue" and "IfFalse" actions in the IF formula are evaluated before checking which one to actually use; in this case, even though the case where division by zero would occur should not have actually been called.
As a workaround, JavaScript can be used to accomplish the same idea. If each of the rating dropdown fields is assigned the CSS class "rating" in the Form Designer, and the Average Rating field is given the "average" CSS class, then the following should work:
$(document).ready(function() {
calcAvg();
$('form').on('blur','.rating',function() {
calcAvg();
});
});
function calcAvg() {
var ratings = [];
$('.rating select').each(function () {
ratings.push($(this).val());
});
var count = 0;
var total = 0;
for (var i = 0 ; i < ratings.length ; i++) {
if (ratings[i] != 'NA') {
total += Number(ratings[i]);
count += 1;
}
}
if (isNaN(total/count))
$('.average input').val("No ratings given");
else
$('.average input').val(total/count);
}
There might be a cleaner way to do it; this was a quick hack.
The aforementioned bug in the IF function of Forms Calculations is targeted for fix in the upcoming Forms 10.1 release.
Thanks for bringing this to our attention.