Cognito-forms – How to conditionally return different value from a Cognito Forms calculation

cognito-forms

I have an if then question. If two numbers equal 50 then 0.
If two numbers equal < 50 then I need the sum of those numbers to be the result.

Best Answer

You can write conditional calculations in Cognito Forms in two ways:

  1. Use if condition then true result else false result
  2. Use condition ? true result : false result

In your case, let's assume you have two number fields, Number1 and Number2. In this case the calculation would be:

=if Number1 + Number2 = 50 then 0 else if Number1 + Number2 < 50 then Number1 + Number2 else ???

In the example above, I left ??? in place for the required final else, because I do not know from your question what should happen when the two numbers are greater than 50. If this is never going to be possible, then you could use the following less complex calculation:

=if Number1 + Number2 = 50 then 0 else Number1 + Number2