Skip to content
GravityKit
Buy
Sign in
0 items
  • Plugins

    GravityKit All Access

    Our complete Kit of essential tools for extending and enhancing Gravity Forms—everything you need to build powerful web apps and workflows.

    Learn more
    • GravityView

      GravityView

      Bestseller

      Display Gravity Forms entries on the front-end of your site and build powerful web applications.

    • GravityImport

      GravityImport

      Trending

      Import entries from CSV files into Gravity Forms to transfer data, create new forms, or update existing entries.

    • GravityEdit

      GravityEdit

      Quickly edit Gravity Forms entries inline to save time, reduce clicks, and streamline your workflow.

    • GravityCharts

      GravityCharts

      Trending

      Turn Gravity Forms entries into interactive charts and graphs.

    • GravityActions

      GravityActions

      Update multiple Gravity Forms entries at once, send bulk emails, and streamline your workflow.

    • GravityCalendar

      GravityCalendar

      Turn Gravity Forms entries into dynamic calendars to showcase events, schedules, appointments, and more.

    • GravityExport

      GravityExport

      Export Gravity Forms entries to Excel, CSV, PDF, or Google Sheets, then share them with secure links or deliver them to cloud storage on a schedule.

    • GravityMath

      GravityMath

      Perform advanced calculations on Gravity Forms entries to display totals, averages, or build custom calculators.

    • GravityRevisions

      GravityRevisions

      Track, compare, and restore changes made to Gravity Forms forms and entries with a full version history.

    • GravityMigrate

      GravityMigrate

      Migrate all Gravity Forms data between sites, including forms, entries, settings, Views, feeds, and file uploads, and import forms from other form plugins.

    • GravityBoard

      GravityBoard

      Manage projects with collaborative project management. Coordinate with your team and streamline your workflows.

    • GravitySearch

      GravitySearch

      Search Gravity Forms entries across every form from one screen.

  • Ideal For

    • Nonprofits
    • Web Agencies
    • Education
    • Developers
    • Small Businesses
    • Startups
    Explore All Use Cases

    Case studies

    • Be There Local
    • Killer Shorts
    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    View All Case Studies
  • Resources

    • Blog
    • Case studies
    • Newsletter
    • GravityKit vs competitors
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy

    Ultimate guides

    • How to use Gravity Forms
    • Editing Gravity Forms entries
    • Importing Gravity Forms entries
    • Exporting Gravity Forms entries
    • Displaying Gravity Forms entries
    • Gravity Forms conditional logic
    • Gravity Forms calculations
    View More Articles
  • Support
  • Pricing
  • Plugins

    • GravityView

      GravityView

      Bestseller

      Display Gravity Forms entries on the front-end of your site and build powerful web applications.

    • GravityImport

      GravityImport

      Trending

      Import entries from CSV files into Gravity Forms to transfer data, create new forms, or update existing entries.

    • GravityEdit

      GravityEdit

      Quickly edit Gravity Forms entries inline to save time, reduce clicks, and streamline your workflow.

    • GravityCharts

      GravityCharts

      Trending

      Turn Gravity Forms entries into interactive charts and graphs.

    • GravityActions

      GravityActions

      Update multiple Gravity Forms entries at once, send bulk emails, and streamline your workflow.

    • GravityCalendar

      GravityCalendar

      Turn Gravity Forms entries into dynamic calendars to showcase events, schedules, appointments, and more.

    • GravityExport

      GravityExport

      Export Gravity Forms entries to Excel, CSV, PDF, or Google Sheets, then share them with secure links or deliver them to cloud storage on a schedule.

    • GravityMath

      GravityMath

      Perform advanced calculations on Gravity Forms entries to display totals, averages, or build custom calculators.

    • GravityRevisions

      GravityRevisions

      Track, compare, and restore changes made to Gravity Forms forms and entries with a full version history.

    • GravityMigrate

      GravityMigrate

      Migrate all Gravity Forms data between sites, including forms, entries, settings, Views, feeds, and file uploads, and import forms from other form plugins.

    • GravityBoard

      GravityBoard

      Manage projects with collaborative project management. Coordinate with your team and streamline your workflows.

    • GravitySearch

      GravitySearch

      Search Gravity Forms entries across every form from one screen.

    View All Products

    GravityKit All Access

    Our complete Kit of essential tools for extending and enhancing Gravity Forms—everything you need to build powerful web apps and workflows.

    Learn more
  • Ideal For

    • Nonprofits
    • Web Agencies
    • Education
    • Developers
    • Small Businesses
    • Startups
    Explore All Use Cases

    Case studies

    • Be There Local
    • Killer Shorts
    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    View All Case Studies

    How to build...

    • Client Portal
    • AI-Built Directory
    • Conference Website
    • WordPress CRM
    • Admin Dashboard
    • Inventory Management
    • Vendor Portal
    • Document Library
    View All Guides
  • Resources

    • Blog
    • Case studies
    • Newsletter
    • GravityKit vs competitors
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy

    ultimate guides

    • How to use Gravity Forms
    • Editing Gravity Forms entries
    • Importing Gravity Forms entries
    • Exporting Gravity Forms entries
    • Displaying Gravity Forms entries
    • Gravity Forms conditional logic
    • Gravity Forms calculations
    View More Articles
  • Support
  • Pricing
0 items

Search

Results appear automatically as you type.
Loading results…

results found matching

    Sign in
    Buy

    Docs

    • Docs Home

    Gravity Forms Add-Ons

    • GravityView
    • GravityActions
    • GravityBoard
    • GravityCalendar
    • GravityCharts
    • GravityEdit
    • GravityExport
    • GravityImport
    • GravityMath
    • GravityRevisions
    • GravitySearch
    • GF Widget for Elementor
    • GF Dynamic Lookup
    • GF Entry Tags
    • GF Event Field
    • GravityExport Lite
    • GF Zero Spam
    • GravityMigrate

    GravityView

    • Getting Started
    • View Setup
    • FAQ
    • Pre-Sale
    • Advanced
    • Common Problems
    • Customizing Your Views
    • Edit Entry
    • Entry Approval
    • Filter and Sort Results
    • Gravity Forms
    • Merge Tags
    • Roles and Capabilities
    • Search
    • Shortcodes
    • View Settings
    • WordPress Posts

    General Help

    • Account, Invoices, and Billing
    • License Related
    • Plugins and Settings
    • Agency accounts
    • Contact
    • Docs Home
    • Gravity Forms Add-Ons

      • GravityView
      • GravityActions
      • GravityBoard
      • GravityCalendar
      • GravityCharts
      • GravityEdit
      • GravityExport
      • GravityImport
      • GravityMath
      • GravityRevisions
      • GravitySearch
      • GF Widget for Elementor
      • GF Dynamic Lookup
      • GF Entry Tags
      • GF Event Field
      • GravityExport Lite
      • GF Zero Spam
      • GravityMigrate
    • GravityView

      • Getting Started
      • View Setup
      • FAQ
      • Pre-Sale
      • Advanced
      • Common Problems
      • Customizing Your Views
      • Edit Entry
      • Entry Approval
      • Filter and Sort Results
      • Gravity Forms
      • Merge Tags
      • Roles and Capabilities
      • Search
      • Shortcodes
      • View Settings
      • WordPress Posts
    • General Help

      • Account, Invoices, and Billing
      • License Related
      • Plugins and Settings
      • Agency accounts
    • Contact

    GravityMath

    • Add calculations to blog posts
    • Calculate the time between two dates with [gravitymath]
    • Calculating Survey fields totals based on their scoring
    • Calculations in GravityView
    • Can GravityMath be used inside a Gravity Forms form?
    • Can I use [gravitymath] with [gvlogic]?
    • Can I use [gravitymath] with Multiple Forms?
    • Debugging calculations in GravityMath
    • Developer Hooks for GravityMath
    • Does GravityMath support the Polls Add-on?
    • Does GravityMath support the Survey Add-on?
    • GravityMath Calculation field
    • How to add field calculations to the table footer
    • How to Calculate the Sum of a Field in Gravity Forms
    • How to display summaries using a block, widget, or shortcode
    • How to enable duration calculations in Gravity Forms with GravityMath
    • How to perform Gravity Forms time calculations in GravityView using GravityMath
    • Math filters: targeting a specific field value with [gravitymath]
    • Nested calculations in GravityMath
    • Pricing fields calculation
    • Sum GravityMath values for today, a custom date range, or a rolling window
    • The [gravitymath] shortcode
    • The {entry_count} merge tag in GravityMath
    • Using GravityMath inside a GravityView Custom Content field
    • When to use GravityMath and when to use GP Advanced Calculations
    • Home
    • Docs
    • GravityMath
    • Using GravityMath inside a GravityView Custom Content field

    Using GravityMath inside a GravityView Custom Content field

    Estimated reading: 4 minutes

    Updated on October 16, 2026

    A [gravitymath] shortcode in a GravityView Custom Content field can calculate over the entries of another form, such as counting each teacher’s lessons in a View of teachers. Before the shortcode runs, GravityView fills in the merge tags in the field with the values of the row’s entry, and a merge tag meant for the other form can be filled in with them.

    When a merge tag is filled in too early #

    GravityView fills in a merge tag when the View’s form has a field with its ID. A merge tag for a field ID that the View’s form doesn’t have is left for GravityMath, which calculates it over the other form. When the View’s form also has a field with that ID, GravityView puts the row’s value of that field in its place. GravityMath then has nothing to count, and the row shows nothing, with no error.

    Example: counting lessons per teacher #

    A music school has two forms:

    • Teachers (form 10), the form the View uses: Name (field 1), Instrument (field 2), and Email (field 3).
    • Lessons (form 20): Lesson (field 1), Date (field 2), Teacher (field 5, the teacher’s name), and Hours (field 6).

    A View of the Teachers form gets a Custom Content field that counts each teacher’s lessons:

    [gravitymath scope="form" id="20" filter="filter_5={Name:1}"]{Lesson:1:count}[/gravitymath]

    {Name:1} belongs to the Teachers form and is meant to be filled in: it puts the row’s teacher in the filter. {Lesson:1:count} belongs to the Lessons form, but the Teachers form also has a field 1, so GravityView fills it in with the teacher’s name, and the column stays empty.

    Counting a field whose ID the Teachers form doesn’t have, such as {Teacher:5:count}, works until someone adds a field 5 to the Teachers form.

    Keeping merge tags for GravityMath with tildes #

    The snippet below lets you write the other form’s merge tags between tildes, such as ~Lesson:1:count~. GravityView leaves those alone, and the snippet turns them back into merge tags right before GravityMath calculates.

    Step 1: Add the snippet

    /**
     * Turns ~Label:ID:modifier~ into {Label:ID:modifier} right before GravityMath
     * calculates, so GravityView leaves those merge tags alone in Custom Content fields.
     *
     * @param string $formula The formula of a [gravitymath] shortcode.
     *
     * @return string The formula with the tilde merge tags turned into merge tags.
     */
    add_filter( 'gravityview/math/shortcode/before', function ( $formula ) {
        preg_match_all( '/~[^~]*?:(\d+(\.\d+)?|[a-z_]+)(:(.*?))?~/mi', $formula, $merge_tags, PREG_SET_ORDER );
    
        foreach ( $merge_tags as $merge_tag ) {
            $updated_merge_tag = str_replace( '~', '', $merge_tag[0] );
            $updated_merge_tag = sprintf( '{%s}', $updated_merge_tag );
            $formula           = str_replace( $merge_tag[0], $updated_merge_tag, $formula );
        }
    
        return $formula;
    } );

    Note: Not sure where to add the code? See Where to put code samples.

    Step 2: Write the merge tags of the other form with tildes

    In the Custom Content field, replace the curly braces of the Lessons form’s merge tag with tildes:

    [gravitymath scope="form" id="20" filter="filter_5={Name:1}"]~Lesson:1:count~[/gravitymath]

    Each teacher’s row now shows their number of lessons. The Hours and Average columns use the examples further down.

    A View of teachers with Lessons, Hours, and Average columns, each calculated by GravityMath from the Lessons form: Dan Ortiz 1 lesson, Ben Carter 2, Ana Lopez 3

    Which syntax to use #

    SyntaxFilled in byUse it for
    {Name:1}GravityView, with the row’s entryA field of the View’s form, such as the value to filter by
    ~Lesson:1:count~GravityMath, after the snippetA field of the form in the shortcode’s id parameter, the form being calculated

    More examples #

    Total hours for the row’s teacher:

    [gravitymath scope="form" id="20" filter="filter_5={Name:1}"]~Hours:6:sum~[/gravitymath]

    Average lesson length, with two decimals:

    [gravitymath scope="form" id="20" filter="filter_5={Name:1}" decimals="2"]~Hours:6:avg~[/gravitymath]

    Filtering by the entry ID of the row #

    When the other form stores the ID of the row’s entry, such as a Teacher ID field (field 7) that holds the teacher’s entry ID, filter on {entry_id}. Put the tilde merge tag in the formula parameter, ahead of the filter:

    [gravitymath scope="form" id="20" formula="~Lesson:1:count~" filter="filter_7={entry_id}" /] lessons for {Name:1}

    With the tilde merge tag after the filter, between the shortcode tags, any merge tag later in the same Custom Content field breaks the row. The row then shows a cut-off shortcode, such as [gravitymath scope="form" id="20" filter="filter_7=Ana Lopez. Gravity Forms reads everything from {entry_id} to that later merge tag as a single merge tag.

    Troubleshooting #

    What you seeWhat to do
    The column is emptyA merge tag for the other form is written with curly braces, and the View’s form has a field with the same ID. Write it with tildes, and check that the snippet is active.
    The column shows 0The filter matches no entries. The field you filter on in the other form has to hold the value the merge tag fills in, such as the teacher’s name.
    The row shows part of a shortcodeA tilde merge tag follows a filter on {entry_id}, and another merge tag comes later in the field. Move the formula into the formula parameter, as in Filtering by the entry ID of the row.

    Related articles #

    • Math filters: targeting a specific field value with [gravitymath]
    Still stuck? How can we help?

    How can we help?

    "*" indicates required fields

    This field is for validation purposes and should be left unchanged.
    Replies will go to this email.
    How can we help?*
    My pre-sale question is related to...*
    My WordPress skills are....*
    My Gravity Forms skills are...*
    You will be shown articles from our documentation.
    Vous pouvez nous écrire dans votre langue maternelle si c’est plus facile pour vous—nous nous occuperons de la traduction!
    Puedes escribirnos en tu idioma nativo si te resulta más fácil; ¡nosotros nos encargamos de la traducción!
    Sie können uns in Ihrer Muttersprache schreiben, wenn das für Sie einfacher ist – wir kümmern uns um die Übersetzung!
    U kunt ons in uw moedertaal schrijven als dat gemakkelijker voor u is — wij zorgen voor de vertaling!
    Du kan skrive til oss på ditt morsmål hvis det er enklere for deg — vi tar oss av oversettelsen!
    Du kan skriva till oss på ditt modersmål om det är lättare för dig — vi tar hand om översättningen!
    Você pode nos escrever em seu idioma nativo se for mais fácil para você — nós cuidaremos da tradução!
    Puoi scriverci nella tua lingua madre se ti è più facile — penseremo noi alla traduzione!
    Please provide as much detail as you're able; this helps us provide you with faster support.
    Drop files here or
    Accepted file types: jpg, jpeg, gif, png, tiff, pdf, bmp, zip, json, csv, xls, xlsx, Max. file size: 256 MB.
      Get better at Gravity Forms every Friday

      Was this page helpful?

      Table Of Contents
      • When a merge tag is filled in too early
      • Example: counting lessons per teacher
      • Keeping merge tags for GravityMath with tildes
      • Which syntax to use
      • More examples
      • Filtering by the entry ID of the row
      • Troubleshooting
      • Related articles
      GravityKit
      • How to Build It
      • GravityKit vs competitors
      • Pricing
      • Products
      • Our Team
      • Our Values
      • Work With Us
      • Partner Directory
      • Coupons
      Support
      • Support
      • Contact
      • Documentation
      • Scope of Support
      • Brand Guidelines
      • Brand Kit
      • Privacy Policy
      • Terms of Service (“Terms”)
      I am a...
      • Nonprofit
      • Web agency
      • Small business owner
      • Web developer
      • Educational institution
      • WordPress freelancer
      • Startup founder
      • One-person agency
      Get notified of updates.

      We’re constantly improving GravityKit. Fill out your email below and we’ll notify you anytime major updates drop.

      See past editions
      • Facebook
      • Twitter
      • Mastodon
      GravityKit is a Gravity Forms Certified Developer.

      Copyright © 2026, Katz Web Services, Inc.

      GravityKit and GravityView are registered trademarks of Katz Web Services, Inc.