ProTip: How to Use Conditional Logic in Automatic Calculations
Level-up your digital forms with Conditional Logic and Automatic Calculations
One of the biggest benefits of a mobile form is automating calculations - it saves you considerable amounts of time by ‘doing the math’ for you and unlike manual calculations, always tallies accurate results. One of the most helpful calculation types in GoFormz is an ‘IF’ function, through which you can apply conditional logic. This IF function directs your mobile form to apply different values when running a calculation, based on specific conditions. A simple example would be a restaurant which charges $0.25 extra for paying by credit card if your subtotal is $5.00 or less. If the subtotal of the bill is more than $5, then no credit card charge.
Because the subtotal is $5.00 or less, the formula automatically adds a $0.25 Credit Card Charge. In other words: IF subtotal<= $5.00 then Credit Card Charge = $0.25
Say the subtotal is $5.01 (a value higher than $5). No Credit Card Charge is added because the subtotal is greater than $5.00.
In order to set up this sort of conditional logic, the values of the “Total” field and the “Credit Card Charge” fields need to be set using calculations. This can be done by setting the Default Value property on each field. The calculation for the Default Value on the “Total” field is simply the sum of the other two fields and looks like this:
The calculation on the “Credit Card Charge” field is more interesting. It’s where you place the conditional logic:
This checks for the condition when the subtotal is greater than 5. If the condition is true then it returns 0, otherwise it returns 0.25.
Basic IF statements are a powerful way to leverage formulas to enforce real-world business rules in your forms. In this way, you can align your mobile forms to help you with many everyday scenarios: maybe you want to apply a specific tax rate based on a zip code entered, or perhaps you want to apply a discount rate based on how many items are purchased.
Checking for various conditions makes calculations a lot more flexible. See our blog post on Dynamic Field Properties for another way you can use conditional checks to save time and ensure correctness.