Sum GravityMath values for today, a custom date range, or a rolling window
Use this pattern when you need the sum of a field’s values over a specific time period โ for example, “total revenue entered today” or “total hours logged between 2026-04-15 and 2026-04-20.” The [gravitymath] ย shortcode’s filter ย parameter only accepts one condition per field, so you can’t express “between two dates” directly. Instead, you nest two shortcodes and subtract.
Before you start #
- You need GravityMath installed and activated.
- You should be comfortable with the
[gravitymath]ย shortcode and itsfilterย parameter. If you aren’t, start with The [gravitymath] Shortcode and Math filters: How to target a specific field value. - You should be using
scope="form"ย orscope="view"ย โ thefilterย parameter only works with those two scopes.
Why you need two shortcodes #
The filter ย parameter can only hold one condition per field. You cannot write filter_date_created=2026-04-15&filter_date_created=2026-04-20 ย and have GravityMath interpret that as a range โ the second condition overwrites the first.
The workaround is to compute two running totals and subtract them:
- The sum of all entries created before the end boundary.
- The sum of all entries created before the start boundary.
Subtracting (1) minus (2) leaves only the entries inside the range.
Both sums use op_date_created=lt ย (“less than”), which excludes the boundary itself. Because lt ย is exclusive, the end boundary must be the day after the last date you want to include.
Sum only today’s entries #
This example sums field ID 6 ย for all entries submitted today, based on each entry’s creation date. Replace id="4" ย with your form ID and {Your Field:6} ย with the merge tag for the field you’re summing.
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=tomorrow&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=today&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]How this works:
- The first inner shortcode sums every entry created before tomorrow (midnight) โ i.e. everything up to and including today.
- The second inner shortcode sums every entry created before today (midnight) โ i.e. everything from yesterday and earlier.
- The outer
[gravitymath]ย subtracts the second from the first, leaving only entries created today.
The today ย and tomorrow ย tokens resolve to midnight on their respective days, so the math lines up cleanly at the day boundary.
Sum entries between two specific dates #
Use this pattern when you need a fixed date range โ for example, a monthly report or a custom reporting window. This example covers 2026-04-15 through 2026-04-20 inclusive:
[gravitymath]
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-21&op_date_created=lt"] {Your Field:6} [/gravitymath2]
-
[gravitymath2 scope="form" id="4" filter="filter_date_created=2026-04-15&op_date_created=lt"] {Your Field:6} [/gravitymath2]
[/gravitymath]Note two things:
- The end boundary is 2026-04-21, not 2026-04-20. Because
ltย is exclusive, you need to pass the day after your last included date. - The start boundary is 2026-04-15 โ the first date you want to include.
lt 2026-04-15ย excludes entries from that day, which is then cancelled out because those entries are also excluded from the end-boundary total.
Date format: use YYYY-MM-DD #
When passing explicit dates into the filter ย parameter, use YYYY-MM-DD ย format (e.g. 2026-04-21 ). Other formats such as d/m/Y ย (e.g. 21/04/2026 ) may not parse reliably, even when that format is what your form’s date field displays to users. The filter_date_created ย comparison runs against the stored entry timestamp, not the displayed format.
The today ย and tomorrow ย relative tokens also work and resolve to midnight of the matching day.
Filtering by a date field in the form, not the submission date #
The examples above filter on filter_date_created , which is Gravity Forms’ built-in entry creation timestamp. If you want to filter on a date field inside the form itself (for example, an “Event date” field with ID 12 ), swap the key:
filter="filter_12=2026-04-21&op_12=lt"Use the field ID in place of date_created , and date values in YYYY-MM-DD ย format.
Troubleshooting #
Symptom: The shortcode outputs 0 ย or a blank value.
Cause: Most often the date format. The filter ย parameter silently fails when it can’t parse the date.
Fix: Re-enter the date in YYYY-MM-DD ย format. If it still fails, enable GravityMath debugging to see how the shortcode is being parsed.
Symptom: The result is off by one day’s worth of entries.
Cause: The end boundary is set to the last day you want included, not the day after.
Fix: Because op_date_created=lt ย excludes the boundary, the end date must be the day after your last included date. For “through 2026-04-20,” use 2026-04-21 .
Symptom: The filter parameter is ignored entirely.
Cause: Missing or incorrect scope set.
Fix: The filter ย parameter only works with scope="form" ย or scope="view" . Pick one and specify the matching form or View id .
Related #
- Math filters: How to target a specific field value โ full
filterย syntax reference, including operators and multi-field conditions. - Nested calculations in GravityMath โ the nesting pattern this article builds on.
- How to Calculate the Sum of a Field in Gravity Forms โ the starting point if you just need a running total with no date filtering.
- The [gravitymath] Shortcode โ full shortcode attribute reference.