You are viewing limited content. For full access, please sign in.

Question

Question

This field contains a calculation error

asked on March 11, 2016

The issue I'm having is that I have a form that has 7 drop downs that I am averaging with the new calculation features but I want the field to be ignored when the selection is "NA" instead of a number. It works when there is at least one number out of the 7 selected. If they are all "NA" it will say "This field contains a calculation error. If it doesn't say that it'll let you submit then gives the error "Cannot divide by zero"

 

Has anyone else seen this, or know of a way to fix it?

0 0

Answer

SELECTED ANSWER
replied on March 18, 2016 Show version history

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.

0 0

Replies

replied on March 11, 2016

Hi Eddie,

This is expected behavior, as you cannot take the average of empty fields. I would try creating a field rule that hides the "Average" field if it is blank. Click here for a video example.

Let me know if this works for you!

0 0
replied on March 14, 2016

I actually thought of that, so I made a rule that hides the field and it appears to work but when you submit you get an error page that says "Cannot divide by Zero"

 

 

0 0
replied on March 14, 2016

Hi there,

You can use the IF clause on top your current formula, to calculate if certain field has value.

0 0
replied on March 14, 2016

So then how would it look if this is my current formula

 

=ROUND(AVG(admissionExp_1,foodServ,housekeep,nurseCare,overall,staffCourt,theraServ))

I though I've tried an IF before but maybe I was doing it wrong.

0 0
replied on March 14, 2016

try this

=ROUND(IF(SUM(admissionExp_1,foodServ,housekeep,nurseCare,overall,staffCourt,theraServ)>0, AVG(admissionExp_1,foodServ,housekeep,nurseCare,overall,staffCourt,theraServ), 0))

 

0 0
replied on March 15, 2016

I'm still getting the error. I think with that if statement it'll still break if all the choices are "NA" which would just make it letters instead of numbers so it can't check if its greater than 0

0 0
replied on March 15, 2016

Can you make the NA choice value to be 0 instead of NA?

0 0
replied on March 15, 2016

I would but the problem is that "0" is already an option... I need it to not factor in the NA at all.

0 0
replied on March 17, 2016

do you know if there would be a way to not run the calculation at all if all the drop downs equal "NA"?

0 0
replied on March 17, 2016

So you just need to change the SUM content to this instead:

SUM(IF(Dropdown1_variable="NA"?,0,1),IF(Dropdown2_variable="NA"?,0,1),...)

0 0
replied on March 17, 2016 Show version history

This is what I have now, and the behavior is the same... did I enter it right?

=ROUND(IF(SUM(IF(admissionExp_1="NA"?,0,admissionExp_1),IF(foodServ="NA"?,0,1),IF(housekeep="NA"?,0,1),IF(nurseCare="NA"?,0,1),IF(overall="NA"?,0,1),IF(staffCourt="NA"?,0,1),IF(theraServ="NA"?,0,1))>0, AVG(admissionExp_1,foodServ,housekeep,nurseCare,overall,staffCourt,theraServ), 0))

When I submit it gives the divide by zero error, and when I change something to a number and back to NA it gives a calculation error.

0 0
replied on March 17, 2016

Can you open a support case and attach this business process?

0 0
replied on March 17, 2016

A case has been opened with Support; this thread will be updated when the issue is resolved.

0 0
replied on May 26, 2016

This has been fixed in Forms 10.0 update 2, you can download the update from https://support.laserfiche.com/kb/kbarticle.aspx?articleid=1013773

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.