How to add a calculated field in Google Form?

How to add a calculated field in Google Form?

Google Forms does not support dynamic calculations, but you can use Formfacade's calculate field option to automatically compute and display the data in real-time to the user filling the form.

Calculated fields allow you to compute a field with values from other fields. Calculated fields can perform arithmetic on number fields, manipulate text & date. For example, you can calculate the total amount in order form based on the order quantity and shipping option chosen by the user.

Let's create a simple order form and learn how to add a calculated field to compute and display the order amount to the user filling the form. Users can order one or more bottles of perfume using the order form. The standard price is $60, but if they order 10 or more bottles of the perfume, the price per bottle is $50. There is a standard shipping fees of $25, but this fees is waived off for orders above $150.

Calculations to be added in the order form:
Product price = $60 for < 10 bottles of perfume; $50 for >=10 bottles of perfume
Order amount = Quantity * Price
Shipping fees = $0 for order amount > 150; $25 for order amount =< 150
Total amount = Order amount + Shipping fees

For example, in my order form, the respective question (field) & parameter references are

1. How many perfumes would you like to order? = entry594415826
2. Your order = entry117609199
3. Order amount = entry1945369676
4. Shipping fees = entry1477669301
5. Total amount = entry1786191165

Arithmetic calculation

Let's start with the basic rules.
1. Any formula/expression in the calculate field option must be written between ${ and }
2. Google Forms stores all answers as string. Use num() function to convert it into number to perform arithmetic operations.

Total amount = order amount + shipping fees. So the expression for calculating would be $(num(entry1945369676)+num(entry1477669301)}

How to use calculate field option?

Conditional IF expression (Ternary operator)

You can use the ternary operator to write conditional IF statements. The ternary operator ?: takes three arguments and is written as follows Condition ? True : False

Let's use this ternary operator to calculate the shipping fees. We must check the order amount to determine the shipping fees. So the expression would be ${num(entry1945369676)>150?0:25}

Similarly, let's calculate the order amount. Order amount = Quantity * Price

Since price is dependent on the quantity ordered, we must use the ternary operator to determine price and then multiply it with quantity to calculate the order amount. So the expression would be ${num(entry594415826)*(num(entry594415826)>=10?50:60)}

Text manipulation

We can show dynamic text based on form fields. We can use ternary operator along with "+" operator to concatenate text. The following expression will give us three different summaries.

${num(entry594415826)>2? "Congrats! You are eligible for free shipping on your order of " + num(entry594415826) + " bottles of perfume." + (num(entry594415826)>10?" You also get a discounted price of $50 per bottle of perfume.":" You will be charged the standard price of $60 per bottle.") : "Thanks for your order. You will charged $60 per bottle of perfume and an additional $25 for shipping."}

#1 Quantity < 2
Thanks for your order. You will charged $60 per bottle of perfume and an additional $25 for shipping.

#2 10 > Quantity > 2
Congrats! You are eligible for free shipping on your order of bottles of perfume. You will be charged the standard price of $60 per bottle.

#3 Quantity >= 10
Congrats! You are eligible for free shipping on your order of bottles of perfume. You also get a discounted price of $50 per bottle of perfume.

Order form

You can test this order form using the link below. https://bit.ly/formfacade