The Bundle Up! Black Friday Sale Is Live!
Countdown timer

Gravity Forms Calculations: The Ultimate Guide

"Gravity Forms Calculations". The Gravity Forms logo next to a graph icon

🚀

Learn how to do calculations in Gravity Forms. This includes advanced calculations, product pricing, date calculations, and how to display tables and charts on the front end.

Estimated reading time: 22 minutes

Gravity Forms is the most powerful form plugin for WordPress. Its calculations functionality is the most powerful in WordPress. Using Gravity Forms, you can perform calculations inside form fields, notifications, and confirmations.

You can also use GravityView and GFChart to display Gravity Forms data on charts or in tables on the front end of your website. Gravity Forms calculations are helpful for event registration forms, product pricing, customer survey reports and any other forms that collect pricing or numerical data.

In this guide, we’re going to explore all the ways to do calculations in Gravity Forms. We’ll look at how to do date and time calculations, the powerful [gv_math] shortcode, and much more!

Why Make Calculations Using Gravity Forms Entry Data?

Performing calculations based on Gravity Forms entries allows you to build a variety of powerful applications. 

There are so many ways to utilize calculations in Gravity Forms. For example, here are some things you can build:

  • Dynamic product pricing form
  • Quote calculator
  • Mortgage calculator
  • Detailed customer survey report

Adding calculations to your Gravity Forms forms helps improve the user experience and reduce the time it takes for you to manually analyze and respond to entries.

For example, instead of writing up quotes for each customer that requests one, you could automate the process by automatically calculating the quote total based on user inputs.

Different Types of Gravity Forms Calculations

There are so many ways to do calculations in Gravity Forms, including:

  • Product pricing
  • Form field calculations
  • Calculations using a shortcode
  • Displaying data and calculations on the front end
  • Calculations based on conditional logic
  • Date and time calculations
  • Displaying data on charts and graphs
  • Survey Calculations

As you can see, Gravity Forms offers a lot of functionality!

Performing Calculations in Gravity Forms

Gravity Forms allows you to do basic calculations based on user input values. You can do calculations within a field by using the Number field.

For example, let’s build a form that can calculate the area of a circle based on its radius. Start by creating a new form in Gravity Forms. You can do this by hovering over Forms and clicking on New Form.

Next, add a Number field to the form, we’ll call it “Circle Radius”, and click “Publish” to save your form. Now add another Number field below your first one called “Circle Area”.

Under Field Settings, check the box that says “Enable Calculation”. In the box below, we’re going to insert our formula. To calculate the area of a circle you multiply pi (~3.14) by the square of the radius.

(Mathematicians, please forgive our approximation of pi! 😁)

The "Enable Calculation" box showing the formula for calculating the area of a circle

As you can see, we’re using a merge tag to reference the user input value from the first field. Then we’re squaring it and multiplying it by 3.14.

After writing your formula, check that it’s valid by clicking Validate Formula.

The Gravity Forms form on the front end with two fields - one for Circle radius and another to output the area

Here’s what our form looks like on the front end. When a user inputs the radius of their circle, Gravity Forms automatically calculates the area and displays it in the Circle Area field.

Product Pricing

You can also perform calculations within a Product field by selecting Calculation under Field Type.

The "Field Type" dropdown menu with "Calculation" selected

If you’re using Gravity Forms to sell products, you can automatically calculate the total cost by using the Total field.

To add a Total field to your form, click on Add Fields, scroll down to Product Fields, and drag and drop the Total field onto your form.

The Gravity Forms "Total" field under "pricing Fields", allowing you to calculate the total price

The total field will automatically calculate the total cost based on the quantity of the different products that a user chooses. 

Product pricing form containing two Product fields and one Total field, displaying the total cost

Gravity Forms Advanced Calculations with the Math by GravityView Plugin

Math by GravityView is a WordPress plugin that allows you to do advanced calculations on your website.

The plugin integrates seamlessly with both Gravity Forms and GravityView, allowing you to:

  • Calculate totals
  • Perform complex functions
  • Count the number of entries in a form (values are always up to date)
  • Display calculations anywhere on your WordPress site
  • Perform calculations based on conditional logic
  • Perform calculations based on product pricing fields

To get started with Math by GravityView, purchase the plugin and install it on your website. If you have a GravityView All Access license, you can install Math by hovering over Views, clicking on Manage Add-ons, and installing Math by GravityView.

The "Math by GravityView" plugin highlighted on the "Manage Add-Ons" page

After activating the plugin, you’ll be able to use the [gv_math] shortcode to perform advanced calculations on your website.

Using the [gv_math] Shortcode

You can use the [gv_math] shortcode to perform pure math calculations without the need for Gravity Forms or GravityView to be installed.

However, if you’re using Gravity Forms field values within [gv_math], here are the accepted parameters:

  • id – The ID of the form, entry, or View (if the scope is defined)
  • scope – This refers to the range of data that you’re working with (either ‘form’, ‘entry’, ‘visible’, or ‘view’)

The plugin also supports several mathematical functions and constants for all types of advanced calculations.

Here are some examples of how it works:

Pure Math:

[gv_math] 5 * 10 [/gv_math]

Output: 50

Get the Total Number of Form Entries

[gv_math scope="form" id="9"] {Number:5:count} [/gv_math]

Get the Highest Field Value

[gv_math scope="form" id="9"] {Number:5:max} [/gv_math]

Mortgage Calculator

To build a mortgage calculator using Gravity Forms and Math by GravityView, create a form in Gravity Forms with input fields for the following values:

  • Home Price
  • Total years to pay back the loan
  • Annual interest rate
  • Number of payments per year

You can then use the [gv_math] shortcode to create a formula that calculates the monthly payment amount. You can output the final value inside a confirmation message, email notification, or inside a View.

Quote Calculator

Does your business offer services such as website design or SEO? You can use [gv_math] to generate quotes and send them to customers.

To create a quote calculator using gravity Forms and Math by GravityView, start by building a form in Gravity Forms that allows users to request a quote for your services.

Include fields allowing users to select different services and packages. You can then use [gv_math] to calculate the cost based on what options the customer chose.

ROI Calculator

Return on Investment or “ROI” is an important business metric that helps you understand the effectiveness of your advertising. Using Gravity Forms’ build in calculation features you can build an ROI calculator for your website. And if you want to take things further, you can use [gv_math] to calculate more complex metrics such as the annualized rate of return.

Adding Calculations to Posts or Pages

You can use the [gv_math] shortcode inside your WordPress pages and posts. Values will dynamically update when new data is added.

All you need to do is edit your page or post and insert your shortcode using a shortcode block. If you’re still using the classic editor, you can simply paste the shortcode where you want the calculation to appear on the page.

A Gutenberg Shortcode block displaying the gv_math shortcode

First off, we’re using scope="form" because we want to work with all the data collected by our form. Next, we’ve added our form ID to the id parameter.

To find your form ID, go to the Forms page and check the ID column on the right-hand side.

Inside our shortcode, we’re using a Gravity Forms merge tag for the Total cost field in our order form. Then we’ve added :avg to get the average total cost of all orders.

When we check the output on the front end, it looks like this:

Output of the calculation on the front end showing "The Average order value is $78"

Now that you know how to use [gv_math] inside a page or post, let’s look at how to use it inside a View in GravityView.

Using [gv_math] Inside a View

The GravityView plugin introduces a new custom post type called a View. Views allow you to display Gravity Forms entries on the front end of your website.

If you have GravityView installed, you can use the [gv_math] shortcode inside a View to display calculations on your website.

Here’s an example of how the shortcode works.

Let’s say we have a form in Gravity Forms that collects product orders and a Table layout View to display order details. We can use [gv_math] to display the total order value for each order.

First, edit your View, scroll down to Entries Fields and add columns for product quantities along with any other details you want to display. 

Next, add a Custom Content field by clicking on the Add Table Column button and selecting Custom Content.

Open up the Custom Content Field Settings by clicking on the gear icon and paste in the [gv_math] shortcode with the following formula.

A GravityView Custom Content field containing the gv_math shortcode for calculating the total cost of an order

Here we’re using scope="entry" because we want to calculate the total order amount for each entry. Inside the shortcode, we’re using Gravity Forms merge tags to work out the total order value by multiplying the quantity and price for each product and then adding together the results.

Here’s what our View looks like on the front end. As you can see, the column on the right is our Custom Content field, which is displaying the total order value for each order.

A GravityView table layout on the front end with four columns - Order ID, Product One, Product Two and Total Amount (shown in dollars).

If you add new entries or make changes to existing entries, the View will automatically update on the front end. 

If you’re displaying entries in a table format using GravityView, you can use Math to add calculations to the table footer

Footer calculations allow you to display the sum, average, max, min, and more for columns in your table without using the [gv_math] shortcode.

First off, make sure you have Math installed. Next, edit your View and click on the gear icon next to one of your fields. Under Display, you’ll see a new checkbox that says “Add field calculations to the table footer?”

After checking this, you’ll see several other options appear, allowing you to customize the footer calculation output.

The footer calculations options, with Calculation Type set as "Average"

You can also change the calculation source. There are three options – View (All), View (Visible), and Form (All)

Choosing View (Visible) will ensure that calculations are done using only the data visible in the table. So if you have multiple pages of data in your table, only the visible page will be taken into account when performing the calculation.

A table showing Names and Ages. The average age is displayed in the footer

Gravity Forms Date and Time Calculations

Are you wondering how to do date and time calculations in Gravity Forms? Here are all the different ways to do it.

Calculating Age Based on Date of Birth Using [gv_age]

If you have GravityView installed, you can use the [gv_age] shortcode inside a View to calculate a person’s age based on their date of birth.

The shortcode takes two parameters:

  • entry_id (the ID of the entry)
  • field_id (the ID of the form field in Gravity Forms)

First, you create a new form that includes a Date field.

The Gravity Forms "Date" field under "Advanced Fields"

Next, create a new View in GravityView. You can place this shortcode inside a Custom Content field to calculate ages for all entries. For the entry_id parameter, you can use the {entry_id} merge tag.

A GravityView custom content field containing the gv_age shortcode for age calculations

Give your custom content field a label, like “age” and update your View. As you can see, the [gv_age] shortcode calculates the age for each entry based on the date of birth.

A table containing three columns - "Name", "Date of Birth" and "Age"

Important: Before you can use [gv_age], you need to add this bit of custom code to your WordPress theme’s functions.php file. How do you do this? There are a few different ways.

1. Using the Theme Editor inside WordPress

Login to your website, hover over Appearance, and click Theme Editor. Next, select the functions.php file under Theme Files on the right.

The Theme Editor page with the "Theme Functions (functions.php)" file highlighted in red

Paste the code at the bottom of the file and click Update File to save it.

2. Using a Plugin

Hover over Plugins, click Add New and search for “Code Snippets”. 

The "Code Snippets" plugin showing 400,000 active installations and a 4.5-star rating from 272 reviews

After the plugin is installed and activated, hover over Snippets in the left-hand menu and click Add New to add a new code snippet to your site.

3. Accessing your website files over FTP

If you’re more technically inclined, you can add custom code to your website using FTP.

FTP stands for File Transfer Protocol and it’s a method for transferring files from one computer to another. To access your website over FTP you’ll need a special software program called an FTP client.

For more information, check this helpful tutorial by WPMarmite.

Date and Time Calculations Using Gravity Perks

Gravity Perks is a suite of add ons for Gravity Forms developed by GravityWiz.

One of the perks that they offer is a date and time calculator add-on that allows you to do date and time calculations in Gravity Forms.

To get started, purchase Gravity Perks and install it on your WordPress website. Next, hover over Forms in the left-hand menu and click on Perks.

Now click on the Install Perks tab at the top and scroll down until you see the GP Date Time Calculator perk.

The Gravity Perks "Date Time Calculator" Perk

After activating the Perk, go to Gravity Forms and create a new form with one or more Date or Time fields.

Now add a Number field to your form and check the box to enable calculations. Inside the text box, you can add date and time field merge tags into your calculations.

The "Enable Calculation" box containing the formula for end date minus start date

This add-on allows you to change the calculation units, count the number of weekdays between dates, and much more.

Displaying Time Calculations on the Front End with GravityView

Earlier, we went over how to do advanced calculations in Gravity Forms using the Math by GravityView plugin. Well, you can also use it to display time calculations inside a View.

First, create a new form in Gravity Forms and add a Single Line Text field. Next, under Field Settings change the Input Mask to either MM:SS or HH:MM:SS.

Highlighting the "Duration (MM:SS)" and "Duration (HH:MM:SS)" options in the Input Mask dropdown menu

Now create a new View using the table layout and add the duration field from your form.

Next, open up the Field Settings by clicking on the gear icon and check the box that says “Add field calculations to the table footer”. You’ll see some new options appear for modifying the time format, changing the calculation type, and more.

In this example, we’ll set it to display the fastest time.

The footer calculations options with "Fastest" selected as the "Calculation Type"

When you’re finished, update your View to save the changes.

A table with two columns - "Name" and "Time to Complete 2km" with the fastest time showing in the table footer

Calculations Based on Conditional Logic

If you have GravityView installed along with Math, you can combine two very powerful shortcodes to perform calculations based on conditional logic.

The GravityView conditional logic shortcode, called , allows you to display information based on parameters that you set. You can use the [gv_math] shortcode inside [gv_logic] to create complex formulas.

Here’s a brief overview of how it works:

[gvlogic if="{product:6}" is="Option One"]
Total cost: [gv_math] 100 + 50 [/gv_math]
[else]
Total cost: [gv_math] 75 + 50 [/gv_math]
[/gvlogic]

Using you can set up different conditions, so your formula will return different results depending on the information submitted by the user.

To find out more about conditional logic in Gravity Forms and the shortcode, read Gravity Forms Conditional Logic: The Ultimate Guide

Creating Charts From Gravity Forms Entries with GFChart

GFChart is an add-on for Gravity Forms that allows you to create and display your Gravity Forms entries on a chart.

GF Chart is a great way to turn your Gravity Forms entries into actionable data. It’s perfect for surveys, assessments, registrations, and sales information.

To get started with GFChart, purchase the plugin and install it on your WordPress website. Next, hover over Forms in the left-hand menu and click on Charts/Calculations.

Give your new chart a name, select a source form and then select a design from the options listed. In this example, we’ll choose the Pie chart.

An arrow pointing to the "Charts/Calculations" page under "Forms" in WordPress

Next, you need to select the form field you want to visualize. You can also apply filters using a date range or conditional logic.

On the Customiser tab, you can give your chart a name, change the height and width and add your own custom CSS code. Finally, when you’re finished, preview your new chart.

A 3-dimensional pie chart with the title "WordPress Rocks". It's split into 5 sections - "Strongly Disagree", "Disagree", "Neutral", "Agree", and "Strongly Agree".

You can also add your chart to a page or post using the WordPress block editor.

First, create a new page by hovering over Pages and clicking Add New. Next, add a Chart block to your page by clicking the plus to add a new block and searching for “Chart”.

The Gutenberg "Chart" block

After clicking the Chart block to add it to your page, make sure to select your form from the dropdown menu.

Dropdown menu with "Pie Chart" selected

That’s it! You can now preview your page on the front end.

Using GFChart Inside a View

The GFChart plugin also integrates with GravityView, allowing you to display charts inside a View.

To add a chart to your View, copy and paste the chart shortcode into a GravityView Custom Content field.

You can find the chart shortcode by hovering over Forms and clicking on Charts/Calculations. You’ll see the shortcode in the column to the right.

The gfchart shortcode on the "Charts/Calculations" page in WordPress

Now edit your View and add a Custom Content field to one of the widget areas.

The "Custom Content" widget in gravityView

Click on the gear icon to bring up the Field Settings window and paste the chart shortcode into the text editor.

Save your View and check it out on the front end. As you can see, the Pie chart displays above our table layout allowing us to visualize data on a chart and in a table.

A pie chart above a table View on the front end

GravityView and GFChart is a powerful combination that allows you to analyze your data in-depth and create beautiful visualizations. For more powerful data analysis capabilities, check out the GravityView DataTables layout.

Gravity Forms Survey Calculations

A survey is an important marketing tool that allows you to learn more about your customers. If you want to conduct surveys on your website using Gravity Forms, you can use the Gravity Forms Survey Add-On.

The survey add-on also integrates with GravityView, allowing you to display surveys on the front end of your website. And if your surveys have scoring enabled, you can use Math by GravityView to display footer calculations based on survey results.

Start by installing the Gravity Forms Survey add-on. Next, create a new form and add a Survey field.

The Gravity Forms "Survey" field highlighted in red

Under Field Settings, check the box that says “Enable Scoring”.

The "Enable Scoring" checkbox next to the Survey fields in Gravity Forms

You’re all set.

Now, create a new View in GravityView and add your survey field. Next, click the gear icon to open the Field Settings and enable footer calculations by checking the box that says “Add field calculations to the table footer?”

Configure the footer calculations by choosing the calculation type and source. Save your View and check it out on the front end. 

A View displaying survey results on the front end with the calculation for average score showing in the footer

As you can see, in this example, we’re displaying the average score across all of our survey entries.

Gravity Forms Calculations: Final Thoughts

In this guide, we explored all the different ways to use calculations inside Gravity Forms.

First, we showed you how to build advanced applications such as automated quote calculators and mortgage calculators. 

Then, we looked at field calculations, pricing calculations, date calculations, and advanced calculations using the [gv_math] shortcode. We also covered how to display calculations on the front end using GravityView and GFChart.

If you found this guide helpful, make sure to subscribe to our blog for everything Gravity Forms!