How to Display Summaries Using [gv_math]

You may want to group Gravity Forms entries by a specific field value and then perform math operations on entries within those groups. 

Here’s an example: You have a donation form on your website allowing users to donate towards different causes (e.g., Science, Education and Medical). Now you want to calculate the total amount donated towards each cause.

This is possible using the [gv_math] "filter" parameter. 

A Gravity Forms form with fields for the name, donation amount and donation category

Constructing the Shortcodes

As you can see, our donation form allows users to enter a custom donation amount and then choose which cause they want their money to go towards (Science, Education or Medical).

Instead of creating a View that displays each donation, we’re going to create a table that summarizes the total amount donated towards each cause.

There’s no way to do this automatically in GravityView, so we’ll need to manually construct a [gv_math] shortcode for each donation category using the filter parameter:

Science: [gv_math scope="form" id="101" filter="filter_5=Science"] {Donation amount:1:sum} [/gv_math]

Education: [gv_math scope="form" id="101" filter="filter_5=Education"] {Donation amount:1:sum} [/gv_math]

Medical: [gv_math scope="form" id="101" filter="filter_5=Medical"] {Donation amount:1:sum} [/gv_math]

We’re using scope=“form” because we’re only working with entries submitted through our donation form (with ID “101”). Next, we’re filtering by the category using the filter parameter filter=“filter_5=Science” (“5” is the ID of the field we want to filter by).

Inside the shortcode, we place the merge tag for the field we want to sum. If we wanted to count the number of entries instead of summing them, we could do that using the count modifier.

Creating the Summary Table

To display these calculations in a table, we’ll edit our page and add a new “Table” block.

The Table block in the WordPress page editor

We’ll create a table with two columns and four rows. We’ll add the donation categories to the column on the left, and then we’ll paste our [gv_math] shortcodes into the column on the right.

A table block in the wordpress editor with [gv_math] shortcodes inside the cells

Here’s what our summary table looks like on the front end:

A table on the front end with donation categories in onecolumn and the total amount donated in another column

When you receive new donations, your table will update to reflect the new amounts.

Filtering by User

You may want to group entries by the user who created them and then perform math calculations on those entries. That’s also possible using the [gv_math] shortcode and the filter parameter. Here’s an example:

[gv_math scope="form" id="101" filter="filter_created_by=1"] {Donation amount:1:sum} [/gv_math]

In this case, the “1” is the user ID of a specific user on your website.

If you need help finding user IDs, read this article

Adding Multiple Filtering Rules

If you want to add multiple filtering rules, you can do so by separating them using “&”. Here’s an example where we’re summing all the Science donations that were sent by a specific user:

[gv_math scope="form" id="101" filter="filter_5=Science&filter_created_by=1"] {Donation amount:1:sum} [/gv_math]

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us