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: 20 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 GravityCharts 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!

Get GravityMath! Perform advanced calculations on your form data – display the number of form submissions, calculate the average age of your respondents, build a front-end calculator, and 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:

Adding calculations to your Gravity Forms forms helps improve the user experience and reduces 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! If you’re feeling overwhelmed, don’t worry. We’ll cover everything you need to know in this post.

Performing Calculations in Gravity Forms (Examples)

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 of the order 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

Quote Calculator

Does your business offer services such as website design or SEO? You can use Gravity Forms calculations to generate quotes and display them in confirmation messages.

To create a quote calculator using Gravity Forms, 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. After assigning different values to different options, you can use Number fields to calculate and display the quote total.

Gravity Forms Advanced Calculations With the GravityMath Plugin

📝 GravityMath 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
GravityMath plugin card

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]

Build a Mortgage Calculator

To build a mortgage calculator using Gravity Forms and GravityMath, 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.

Build an ROI Calculator

Return on Investment or “ROI” is an important business metric that helps you understand the effectiveness of your advertising. Using Gravity Forms’ built-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 also 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

The above shortcode will calculate and display the average order value. We’re using scope="form" because we want to work with all the data collected by our form. As you can see, we’ve also added our form ID to the id parameter.

💡 Pro tip: 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

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

📝 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.

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. 

Footer Calculations

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, and min 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’s what you need to know.

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 GravityMath plugin. Well, you can also use it to display time calculations on the front end using GravityView.

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

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.

📝 Important: Before you can use [gv_age], you need to add this bit of custom code to your WordPress theme’s functions.php file.

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"

Calculations Based on Conditional Logic

If you have GravityView installed along with GravityMath, 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]
Total cost: [gv_math] 75 + 50 [/gv_math]

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 [gvlogic] shortcode, read Gravity Forms Conditional Logic: The Ultimate Guide.

Creating Charts From Gravity Forms Entries Using GravityCharts

Using our GravityCharts plugin, you can extract actionable insights from your Gravity Forms data. It’s perfect for surveys, assessments, registrations, and sales information.

📝 GravityCharts is an add-on for Gravity Forms that allows you to create charts and graphs using your Gravity Forms data.

After installing GravityCharts, edit your form and create a new chart feed.

GravityCharts feed

After giving your new chart a name, select a chart type from the available options. In this example, we’ll choose the Bar / Column chart.

selecting a chart type in GravityCharts

Next, you need to select a data source (i.e., the form field you want to visualize). You can also use conditional logic to filter the data by criteria that you set.

Selecting a data source

Now scroll down to the Chart Configuration panel. Here you can customize the look and feel of your chart while viewing a live-updating chart preview.

The chart configuration panel in GravityCharts
  1. Colors – Select from one of our predefined color palettes. 
  2. Design – Customize the look of your chart.
  3. Title & Legend – Add a title and legend to your graph.
  4. Axis – Hide grid lines and enable auto-scaling.
  5. Live-updating chart preview.

When you’ve finished customizing the design of your chart, save the feed. You can now embed your chart on the front end by adding a GravityCharts block to your page layout.

The GravityChats block in the WordPress block editor

That’s it! Now you can preview your new chart on the front end. As you receive new form submissions, your chart will update automatically.

A graph displaying data collected via Gravity Forms

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 GravityMath to display footer calculations based on survey results.

To create your first survey, 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!

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 chart and graphs on the front end using GravityCharts.

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