Gravity Forms Advanced Calculations
Perform advanced calculations with mathematical functions, conditionals, and a powerful formula editor.
What does it do?
Advanced Calculations completely revamps calculations in Gravity Forms. Not only does it empower you with advanced mathematical functions and conditionals, it improves the formula editing experience with a powerful new editor, complete with syntax highlighting, autocompletion, shorthand field references, and so much more!
With Advanced Calculations you can create:
- Mortgage calculators
- Advanced calculated products
- Auto loan calculators
- Investment/Retirement calculators
- BMI calculators
- And many more!
Features
- Heaps of mathematical functions.
Spreadsheet style math directly in your form. - Conditional statements.
Specify multiple formulas in the same field; use the right one based on your conditions. - Formula shorthand.
Simplify your formulas with our field reference shorthand. No more cumbersome merge tags! - Syntax highlighting.
Clarify your complex formulas and spot issues quickly with automatic syntax highlighting. - Secure, tamperproof calculations.
All calculations are recalculated on submission for accuracy and security. - Seamless integration.
Automatically enhances all calculation-enabled fields like Number and Calculated Product fields. - Automatic updates.
Get updates and the latest features right in your dashboard. - Legendary support.
We’re here to help! And we mean it.
Documentation
How do I enable this functionality?
After installing and activating Gravity Forms Advanced Calculations,
Add a Number field to your form. | |
Check Enable Calculation. | |
Insert advanced calculations into form. Use the Formula Cheatsheet for a primer on calculations. |
Feature Details
Merge Tag Shorthand
The true power of calculations with Gravity Forms comes from being able to reference other fields to create calculations from what users have entered. Gravity Forms uses merge tags to reference fields. Merge tags are referenced using the field ID, with or without the descriptor, such as {Field A:1}
or {:1}
.
Gravity Forms Advanced Calculations adds shorthand for fields to clean up your calculations and make it easier to keep track of everything. The shorthand for the same field shown above is written as F1
.
Shorthand offers more readable calculations, especially for complicated functions.
Conditional Statements
Advanced Calculations supports conditional statements such as if/else and if/elseif/else. Use these statements to evaluate calculations based on field values.
if/else
if( F1 > 1.25 && F1 < 5.5 ):
F1 * 50
else:
0
endif;
if/elseif/else
if( F1 < 5.5 ):
F1 * 50
elseif( F1 >= 10 ):
F1 * 25
else:
0
endif;
You may use as many elseif
statements as needed. You are not limited to one.
Supported Operators
The following comparison operators are supported:
==
Equal to!=
Not equal to>
Greater than<
Less than>=
Greater than or equal to<=
Less than or equal to
Multiple Expressions
Conditional statements support multiple expressions within a single condition via the the &&
(and) or the ||
(or) operators.
To require both expressions to be true for the condition to match, you would use the &&
operator. In this example, the condition will only be true if Field #1 is greater than 5 and less than 10.
if ( F1 > 5 && F1 < 10 ):
If you would like your condition to match if any of the conditions are true, you would use the ||
operator. In this example, the condition will return true if Field #1 is greater than 5 or if Field #2 is greater than 5.
if ( F1 > 5 || F2 > 5 ):
While these examples are simple, this functionality is quite robust and can handle conditions that contain expressions with both &&
and ||
operators.
Syntax Highlighting
Advanced Calculations adds syntax highlighting and autocompletion to the calculation text area. Syntax highlighting drastically improves the readability of calculations, especially complicated ones that use conditional statements and functions.
Autocompletion aids you when inputting a function or conditional statement. When you start typing any supported function, the editor will suggest a completion. Click the suggested function (or hit return) to insert the full function with placeholder values.
The editor also automatically closes parentheses and merge tag braces. Say goodbye to invalid formulas because of an errant parenthesis!
Tooltips
When hovering over shorthand field variables and merge tag field variables with no descriptor in the formula editor, you will see a tooltip displaying the field’s label.
Functions
Advanced Calculations adds support for common functions to both save you time and effort and provide more accurate results.
Absolute Value – abs
Returns the absolute value of a number.
Sample Usage
abs( -78 )
abs( F1 )
Syntax
abs( value )
value
– The value or field of which to return the absolute value.
Example
In the below example, the retuned value is 14
.
abs( -14 )
Average – average
Returns the average value of the arguments given.
Sample Usage
average( F1, F2, 26 )
average( 1, 2, 3, 4, F1 )
Syntax
average( value1, [value2, ...] )
value1
– The first value or field to evaluate when calculating the average value.value2, ...
(optional) – Additional values or fields to evaluate when calculating the average value.
Example
In the below example, the returned value is 35
.
average( 12, 58, 35 )
Ceiling – ceil
Rounds a number up to the next largest integer.
Sample Usage
ceil( 25.4 )
ceil( F1 )
Syntax
ceil( value )
value
– The value to round up to the nearest integer.
Example
In the below example, the retuned value is 36
.
ceil( 35.8 )
Exponential – exp
Returns e^x, where e is Euler’s number (~2.718) and x is the provided value.
Sample Usage
exp( 25.4 )
exp( F1 )
Syntax
exp( value )
value
– The exponent to raise e to.
Example
In the below example, the retuned value is 148.4131591025766
.
exp( 5 )
Floor – floor
Rounds a number down to the nearest integer.
Sample Usage
floor( 75.763 )
floor( F3 )
Syntax
floor( value )
value
– The value to round down to the nearest integer.
Example
In the below example, the retuned value is 323
.
floor( 323.78 )
Future Value – fv
fv
calculates the future value of an investment based on constant-amount periodic payments and a constant interest rate.
Sample Usage
fv( F1, F2/12, F3, 10000, 1 )
fv( 0.05, 10, F1, F2 )
Syntax
fv( rate, numberOfPeriods, paymentAmount, presentValue, [endOrBeginning] )
rate
– The annualized rate of interest.numberOfPeriods
– The number of payments to be made.paymentAmount
– The amount per period to be paid.presentValue
– The current value of the investment.[endOrBeginning]
– (optional – 0 by default) – Whether payments are due at the end (0) or beginning (1) of each period.
Units must be consistent for rate
, number_of_periods
, and payment_amount
. For example, on a 60 month car loan this is paid monthly, the rate
should be divided by 12 and the numberOfPeriods
is 60. If the same loan was instead paid quarterly, the rate
should be divided by 4 and the numberOfPeriods
is 20.
Example
In the below example, the retuned value is 0.023
.
fv( 0.0311, 60, 450, -25000, 0 )
By default fv
calculates a loan. To use it to calculate a growing investment, add a minus before the formula. For example:
-( fv( 0.08, 5, 300, 2500 ) )
Natural Logarithm – ln
ln
returns the logarithm of a number, base e. e is Euler’s number (~2.718).
Sample Usage
ln( 23 )
ln( F4 )
Syntax
ln( value )
value
– The value to calculate the logarithm, base e.value
must be positive.
Example
In the below example, the retuned value is 6.19644412779452
.
ln( 491 )
Logarithm – log
log
returns the logarithm of a number, base 10.
Sample Usage
log( 7 )
log( F2 )
Syntax
log( value )
value
– The value to calculate the logarithm, base 10.value
must be positive.
Example
In the below example, the retuned value is 1.6901960800285136
.
log( 49 )
Maximum – max
max
returns the largest value in the list of arguments.
Sample Usage
max( F1, F4, 67 )
max( 108, F7 )
Syntax
max( value1, [value2, ...] )
value
– The first value or field to evaluate when calculating the maximum value.[value2, ...]
– (optional) – Additional values or fields to evaluate when calculating the maximum value.
Example
In the below example, the retuned value is 49
.
max( 36, 49 )
Minimum – min
min
returns the smallest value in the list of arguments.
Sample Usage
min( F3, 56, F8 )
min( 3, F1 )
Syntax
min( value1, [value2, ...] )
value
– The first value or field to evaluate when calculating the minimum value.[value2, ...]
– (optional) – Additional values or fields to evaluate when calculating the minimum value.
Example
In the below example, the retuned value is 6
.
min( 18, 6 )
Pi – pi
pi
returns the value of pi to 20 decimal places.
Sample Usage
pi()
Syntax
pi()
Example
In the below example, the retuned value is 3.14159265358979323846
.
pi()
Round – round
round
rounds a number to the nearest integer.
Sample Usage
round( 12.7 )
round( F2 )
Syntax
round( value )
value
– The value to round to the nearest integer.
Example
In the below example, the retuned value is 9
.
round( 8.68 )
Square Root – sqrt
sqrt
returns the square root of a number.
Sample Usage
sqrt( F12 )
sqrt( 72 )
Syntax
sqrt( value )
value
– The number to calculate the square root.
Example
In the below example, the retuned value is 12
.
sqrt( 144 )
Known Limitations
- Non-numeric values are not supported in conditional statements.
Integrations
Invoicing Templates by Gravity PDF
GP Advanced Calculations integrates with Gravity PDF’s Invoicing 2.0+ templates. These templates allow for business-ready invoice generation from Gravity Forms submissions. They’re highly customizable, translatable, support conditional logic, and are GST/VAT compatible. This integration allows for GP Advanced Calculations’ mathematical functions and formulas to be leveraged while working with Gravity PDF’s Invoicing templates.
There’s a variety of sleek templates to choose from and all templates integrate with GP eCommerce Fields, GP Inventory, GP Conditional Pricing, GP Unique ID, and GP Price Range. Learn more about Gravity PDF’s invoicing templates here.
Translations
You can use the free Loco Translate plugin to create translations for any of our Perks. If you’ve never used Loco translate before, here’s a tutorial written for beginners.
FAQs
No FAQs yet. What do you want to know?
Hooks
Gravity Forms has hundreds of hooks. Check out our Gravity Forms Hook Reference for the most thorough guide to Gravity Forms’ many actions and filters.
Related Resources
- How to Do Calculations with Gravity Forms
If you’re using Gravity Forms on your WordPress website, you might need an easy way to do Gravity Forms calculations on form fields and user submissions. - Spotlight: Building a Loan Calculator with GP Advanced Calculations
See how James Roberts built a loan calculator for an auto-financing company using GP Advanced Calculations. - Spotlight: Creating Dynamic, Customizable Quoting Forms with Jennifer Erdman
We explore how Jennifer Erdman built a quote calculator — based on highly customizable product offerings — step by step.