## đ

*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!

## Table of contents

- Why Make Calculations Using Gravity Forms Entry Data?
- Different Types of Gravity Forms Calculations
- Performing Calculations in Gravity Forms
- Gravity Forms Advanced Calculations with the Math by GravityView Plugin
- Gravity Forms Date and Time Calculations
- Calculations Based on Conditional Logic
- Creating Charts From Gravity Forms Entries with GFChart
- Gravity Forms Survey Calculations
- Gravity Forms Calculations: Final Thoughts

## 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! đ)

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

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

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 total field will automatically calculate the total cost based on the quantity of the different products that a user chooses.

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

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.

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:

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.

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.

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

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.

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

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.

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.

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

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

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.

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.

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

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.

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

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

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.

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

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

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.

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

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.

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.

Under *Field Settings*, check the box that says âEnable Scoringâ.

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.

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!