Calculations: Advanced Logic - Gavel

Calculations

Calculations — previously called Invisible Logic — let you create new variables whose values Gavel computes automatically, without asking the client another question. You define a formula or a set of conditional rules, and Gavel evaluates them behind the scenes to produce a value that you can use anywhere in your document templates or question logic. This is the tool to reach for whenever you need to derive information from what the client already told you, rather than asking for it directly. You access Calculations from the Calculations page at the top of the screen when editing a workflow.

Why use Calculations?

Creating a Calculation variable

  1. Open the Calculations page: While editing your workflow, click the Calculations tab at the top of the screen.
  2. Create a new variable: Add a new Calculation variable and give it a name. Choose the variable type (Text, Number, Date, etc.) to match the kind of value you want to produce.
  3. Enter the fallback formula: In the formula field, enter the value the variable should have when no specific condition is met. For a conditional variable, this is typically an empty string " ". For a straightforward formula with no conditions, enter the expression directly here.
    • Click Enter text to type a text literal (Gavel adds the quotation marks)
    • Click Enter space to insert a blank space " "
    • Click a variable name (prefixed with @) to reference any existing variable
    • Scroll down to find functions such as add, concatenate, or format date
  4. Add conditional logic (optional): Click Add Logic to define conditions under which the variable should take a different value. Each condition specifies: when [variable] equals [value], set this Calculation variable to [output]. You can group multiple Calculation variables together and apply the same logical condition to all of them at once — useful when a single condition (such as gender) drives several related variables (pronoun, possessive, title).

Referencing Calculation variables in documents

You reference Calculation variables in your DOCX or PDF templates using the same double-curly-bracket syntax you use for any regular questionnaire variable:

{{ CalculationVariableName }}

Calculation variables work seamlessly across your entire workflow — in document templates, question logic conditions, and instruction blocks.

Setting conditions for pronouns

Handling pronouns is one of the most common Calculations use cases in legal document automation. Instead of scattering conditional logic throughout your template, you create a small group of pronoun variables in Calculations and then reference those variables everywhere a pronoun appears.

  1. Ask for gender: Add a single-select question with a variable such as ClientGender and choices like Male, Female, and Non-binary.
  2. Create a pronoun Calculations group: In Calculations, create a group of new variables for the pronoun forms you need. For a will or trust, you might create:
    • ClientPronounSubject (He / She / They)
    • ClientPronounPossessive (His / Her / Their)
    • ClientTitle (Testator / Testatrix / Testator)
  3. Set the conditional logic: Add logic to the group:
{{ ClientTitle }} hereby declares that {{ ClientPronounSubject }} is of sound mind and wishes to dispose of {{ ClientPronounPossessive }} estate as follows.

Numerical calculations

For numeric computations in your document templates, you can write mathematical expressions directly in your template using double curly brackets. Make sure the source questions use the Number or Integer question type.

When combining rounding with number formatting, place the rounding call inside the parentheses:

{{ "{:,.0f}".format(variablename|round(0,'ceil')) }}

Date calculations

Gavel provides a full set of date-calculation functions you can use directly in document templates.

Calculate age or time elapsed

{{ (date_difference(starting=DateVariable).years|int) }}

Calculate between two specific dates

{{ (date_difference(starting=StartDate, ending=EndDate).years|int) }}

Add or subtract days, months, or years

{{ format_date( (DateVariable) + date_interval(years=2) ) }}

Add or subtract business days

{{ format_date( (DateVariable) + date_interval(bus_days=10) ) }}

Calculate months between two dates

{{ (relative_date_difference(starting=StartDate, ending=EndDate).months) }}

Find the next or prior business day

{{ next_business_day(DateVariable) }}
{{ prior_business_day(DateVariable) }}

Date-based conditional eligibility

You can use Calculations to create eligibility date variables and then drive page logic from them. For example:

eligibility_date = today() - date_interval(years=18)

Display conditional messages based on dates (in questions)

In instruction blocks within your questionnaire, you can show different text based on a date comparison:

${ "We are sorry. You are too late." if date_difference(starting=FilingDate).days > 30 else "Great. Let's continue." }