How to Evaluate Values and Logical Conditions in Microsoft Word Using the COMPARE Field

Creating dynamic and automated templates in Microsoft Word often requires evaluating conditional statements, such as checking whether an invoice total exceeds a budget, verifying date thresholds, or toggling clause visibility in contracts. While the standard IF field code provides basic branching, complex numeric comparisons or multi-condition evaluations can become unwieldy. The COMPARE field code is a dedicated logical operator in Microsoft Word designed specifically to evaluate relational expressions between two values. When executed, COMPARE returns a binary result (1 for true and 0 for false), making it an ideal building block for dynamic formulas, contract conditions, and nested mail-merge logic.

Understanding the Syntax of the COMPARE Field

The COMPARE field takes two expressions separated by a relational comparison operator. The basic syntax inside Word field code delimiters is:

{ COMPARE Expression1 Operator Expression2 }

Word evaluates the comparison and returns an integer:

  • 1: The condition is true.
  • 0: The condition is false.

The field supports standard comparison operators:

  • = : Equal to
  • <> : Not equal to
  • > : Greater than
  • < : Less than
  • >= : Greater than or equal to
  • <= : Less than or equal to

Inserting the COMPARE Field Manually in Word

Because the COMPARE field is primarily a calculation engine, inserting it via keyboard shortcuts ensures precise control over nested values:

  1. Place your cursor where you want the logical evaluation to occur.
  2. Press Ctrl + F9 (or Cmd + F9 on macOS) to insert the field code braces { }.
  3. Inside the braces, type the COMPARE statement. For example, to compare whether 150 is greater than 100:
    { COMPARE 150 > 100 }
  4. With your cursor inside the field braces, press F9 to evaluate the expression. Word renders 1 because the condition is true.
  5. Press Shift + F9 to toggle between the raw formula and the rendered result.

Comparing Dynamic Bookmarks and Variables

The true utility of COMPARE appears when evaluating dynamic values rather than static numbers. You can reference document bookmarks, form fields, or document properties within the comparison:

Suppose you have bookmarked a proposed fee as TotalAmount and a credit limit as CreditLimit. To evaluate whether the amount exceeds the limit:

{ COMPARE { REF TotalAmount } > { REF CreditLimit } }

If the fee exceeds the credit limit, the field returns 1; otherwise, it returns 0.

Nesting COMPARE Inside IF Fields for Custom Text Output

While COMPARE returns 1 or 0, you frequently need to display human-readable text (such as “Approved” or “Exceeds Budget”) based on that outcome. You can nest the COMPARE field directly inside an IF field:

{ IF { COMPARE { REF TotalScore } >= 70 } = 1 "Passed" "Requires Retest" }

In this nested structure:

  1. Word first evaluates { COMPARE { REF TotalScore } >= 70 }, returning either 1 or 0.
  2. The outer IF field checks whether that result equals 1.
  3. If true, Word prints Passed. If false, Word prints Requires Retest.

Evaluating Text Strings with COMPARE

The COMPARE field is not limited to numbers; it can also evaluate text strings alphabetically. When comparing text, wrap both expressions in double quotes:

{ COMPARE "London" = "London" }

This evaluates to 1. You can also evaluate alphabetical order (e.g., determining if a surname falls before “M” for directory splitting):

{ COMPARE "Baker" < "Miller" }

Because “Baker” precedes “Miller” alphabetically, this returns 1.

Troubleshooting COMPARE Field Errors and Recalculation

When working with logical fields in Word, observe the following practices to avoid calculation errors:

  • Missing Field Braces: Never type curly brackets { } manually from the keyboard. Always press Ctrl + F9 to create each pair of delimiters, including nested sub-fields.
  • Spaces Around Operators: Always include spaces around the relational operator (e.g. A > B, not A>B). Without spaces, Word may interpret the expression as a single malformed token.
  • Updating Fields: Fields do not recalculate automatically when you type. To refresh all comparisons across your document, press Ctrl + A followed by F9.
  • Print Verification: To ensure all conditional statements evaluate accurately when exporting to PDF or printing, enable Update fields before printing under File > Options > Display.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.