---
title: "How to Calculate the Sum of a Field in Gravity Forms"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravitymath/how-to-calculate-the-sum-of-a-field-in-gravity-forms/"
---

Using the [ shortcode](https://www.gravitykit.com/docs/gravitymath/math-shortcode/) you can calculate the sum of a field for all entries in a form.

### Prefer to Watch the Video?

https://www.youtube.com/watch?v=ynqJIGlMPmg We need two things to find the sum of a field for all form entries:

- The Form ID
- The Merge Tag of the field we want to sum

The shortcode will look like this:

```

[gravitymath scope="form" id="4"] {merg tag:2} [/gravitymath]
```

```

[gravitymath scope="form" id="4"] {merg tag:2} [/gravitymath]
```

`scope="form"` tells the shortcode that we’re working with data from a form (as opposed to a View). The `id` value refers to the ID of your form in Gravity Forms and the merge tag should be the merge tag of the field you want to sum. Merge tags are always wrapped in curly brackets.

**Note:** The default behavior for `[gravitymath]` is to output a sum. If you want to output a count instead, you can use the `:count` operator, like this: `{merge_tag:2:count}`.

## Finding Your Form ID: 

Hover over *Forms* in your WordPress admin menu and click on *Forms*, you’ll see the form ID in the first column on the right.

![Dashboard listing forms with IDs emphasized for calculation reference](https://www.gravitykit.com/wp-content/uploads/2025/10/file-nuhvrsHAqW.png)

## Finding the Field’s Merge Tag

Here's an easy way to find the merge tag for any field in your form.

From the form editor, hover over *Settings* at the top and click on *Notifications*.

![Gravity Forms settings menu open, highlighting the Notifications option](https://www.gravitykit.com/wp-content/uploads/2025/10/file-LwU4Bih3D2.png)
Now, click *Add New* to create a new notification (we’re not going to save it, we’re only using this as a way to get the merge tag!)![Notifications settings page with an "Add New" button highlighted](https://www.gravitykit.com/wp-content/uploads/2025/10/file-DpSjcE2sj3.png)
*Scroll down to the text editor and click on the merge tag button on the right*![Gravity Forms interface showing Visual and Text tabs with an arrow pointing to code button](https://www.gravitykit.com/wp-content/uploads/2025/10/file-fgpV0KLFGz.png)
*Now, select the name of the field you want to sum from the list*![Dropdown menu in Gravity Forms; user selects "Number of Attendees" field](https://www.gravitykit.com/wp-content/uploads/2025/10/file-y0sZF93xD7.png)
*You'll see the field merge tag appear in the text editor. Copy it to add to your shortcode*![Editor displaying field placeholder "{Number of Attendees:4}" in Gravity Forms](https://www.gravitykit.com/wp-content/uploads/2025/10/file-6qqVorEoMh.png)

## Displaying the Sum of a Field on Your Website

You can add the `[gravitymath]` shortcode anywhere on your website!

As you can see, here we’ve added it to a new page.

![Guests attending shown with a Gravity Forms math shortcode for calculating number of attendees](https://www.gravitykit.com/wp-content/uploads/2025/10/file-QlJC97aenU.png)
*And on the front end, the shortcode is replaced with the sum of all values in the field*![Text shows guest count for a Space Station event and links to an online store for flight suits](https://www.gravitykit.com/wp-content/uploads/2025/10/file-AOnz02BKp2.png)

## Adding the Shortcode to a View

You can add the `[gravitymath]` shortcode to a View by pasting it inside a Custom Content field or widget.

To do this, go to your View editor, click the *Add Widget* button and select *Custom Content*.

![Add Widget options in Gravity Forms: Search Bar, Custom Content, Gravity Forms, and Page Size](https://www.gravitykit.com/wp-content/uploads/2025/10/file-2SdsaLlj7D.png)
*Next, open the widget settings by clicking on the gear icon. Now, paste the shortcode inside the text editor along with any other text/HTML you want to display*![Using Gravity Forms shortcode to calculate total guest count](https://www.gravitykit.com/wp-content/uploads/2025/10/file-MFXDFSe4OQ.png)
*As you can see, the shortcode is replaced on the front end*![Total number of guests attending is shown as six, with buttons for copy, CSV, and print](https://www.gravitykit.com/wp-content/uploads/2025/10/file-JohTprwqHO.png)
To learn more about `[gravitymath]` and how to perform advanced calculations, read our ultimate guide to[Gravity Forms calculations](https://www.gravitykit.com/gravity-forms-calculations/#h-gravity-forms-advanced-calculations-with-the-math-by-gravityview-plugin).