Knowledge Center

Knowledge Center > Billing and Payments > Invoices > Creating a Custom Invoice Template > Conditional Logic (IF Fields)

Conditional Logic (IF Fields)

Using Conditional Logic on Invoice Templates

The number of invoice templates your business needs can increase with every new payment method, seasonal discount, and more. Consolidate invoice templates by using conditional logic. Based on customer information or charge attributes, you can display different pieces of information on an invoice. For example, you can display different instructions based on a customer’s payment method:

Conditional logic example.png

What are IF Fields?

You must upgrade your invoice templates to the new invoice file generation service to use IF fields. For instructions on how to upgrade, see Upgrade to New Invoice File Generation Service.


IF fields contain IF/THEN logic that allows you to customize what is displayed on a customer's invoice based on the value of a merge field. For example, you can display the price of an invoice item as a numerical dollar amount, or, if the amount is zero, display "FREE".

See Customize Invoice Templates Using Word Mail Merge for information on how to insert merge fields into an invoice template.

What IF Fields Can't Do

  • IF fields cannot hide or display specific table columns or rows.
  • IF fields cannot hide or display recursive tables.

IF Field Syntax

IF fields test the value a merge field (the test condition), then display different results depending on whether the test result is true or false. The format of an IF field is:

{ IF [Test Condition] [Result Displayed if TRUE] [Result Displayed if FALSE] }

The result displayed can be text, the value of a merge field, a table, or nothing.

See Merge Fields Supported in IF Fields on Invoice Templates for information on which merge fields you can use with IF fields.

For more information on using IF fields, go to the Microsoft Office Support Center

Example Use Cases 

Example 1: Display Text or a Merge Field​​ Value

The IF field in this example tests InvoiceItem.ExtendedPrice to see if the value of the merge field equals 0. If the value equals 0, the test returns true and the IF field displays "FREE" on the invoice. If the value of the field does not equal 0, then the IF field displays the value of the merge field InvoiceItem.ExtendedPrice on the invoice instead.

{ IF {MERGEFIELD InvoiceItem.ExtendedPrice \* MERGEFORMAT​} = 0 "FREE" {MERGEFIELD InvoiceItem.ExtendedPrice \* MERGEFORMAT​} }

Add the \* MERGEFORMAT switch to the end of all fields, including IF fields. The switch ensures that any formatting you apply to a result displayed by a field is retained in subsequent results.


Here is what the invoice might look like when the IF field in this example is used in the TOTAL column of a Rate Plan Summary table:

Subscription Identifier Rate Plan Name Subtotal Tax TOTAL

A- S00000010

Data Plan




A- S00000010

Cable Plan




A- S00000011

Data Plan




A- S00000011

Cable Plan




Example 2: Display Nothing or a Merge Field Value

The IF field in this example tests Invoice.Discount to see if the value of the merge field equals 0. If the value equals 0, the test returns true, and the IF field does not display anything on the invoice. If the value of Invoice.Discount does not equal 0, the test returns false, and the IF field displays "You saved $X this month" (where X is the value of Invoice.Discount).

{ IF {MERGEFIELD Invoice.Discount \* MERGEFORMAT} = 0 "" "You saved {MERGEFIELD Invoice.Discount \* MERGEFORMAT} this month." }

The IF field displays nothing if the result is two consecutive double quotes ("").


Here is what the invoice might look like when this IF field is used to display the Invoice Discount in an Invoice Summary table:


Invoice Number








Invoice Discount

You saved $20.00 this month

Example 3: Display a Table or Nothing

You may want to display a table only to customers in a certain country. In this example, the table is displayed only on invoices for customers from the United States.

The IF field tests BillToContact.Country to see if the value of the merge field equals "United States". If the value does equal "United States", the IF field displays the table. If it does not equal "United States", the IF field displays nothing.

If there are spaces in the condition or result text (such as "United States"), you must wrap the text in double quotes.


{ IF {MERGEFIELD BillToContact.Country \* MERGEFORMAT} = "United States"

Tax Name Tax Rate Tax Rate Type Tax Amount


Here is what the invoice might look like for customers from the United States:

Tax Name Tax Rate Tax Rate Type Tax Amount
tax1 0.1 Percentage $10.00

How to Create an IF Field

This example shows you how to construct the following IF field:

IF {MERGEFIELD InvoiceItem.ExtendedPrice \* MERGEFORMAT} = 0 "FREE" "" \* MERGEFORMAT }

The IF field displays the text "FREE" if the value of InvoiceItem.ExtendedPrice equals 0. Otherwise, the IF field displays nothing.

To construct this IF field:

  1. Move the cursor to where you want to insert the IF field. Press Ctrl + F9 (or command + fn + F9 on a Mac)​ to insert curly braces. Then type IF into the braces:

{ IF } 

IF fields are contained within curly braces. You must insert the curly braces into your invoice template by pressing Ctrl + F9 (or command + fn +F9 on a Mac). You cannot just type the curly braces.

  1. Type a space after IF, then insert the InvoiceItem.ExtendedPrice merge field. Insert the merge field as described in Customize Invoice Templates Using Word Mail Merge. You cannot just type the merge field into the curly braces. 

{ IF {MERGEFIELD InvoiceItem.ExtendedPrice \* MERGEFORMAT}​ }

If the merge field formatting appears different to the example, you may be in the field result view. To toggle to the field code view, press Alt + F9 (or option + fn + F9​ on a Mac).

  1. Type in the rest of the merge field:

{ IF {MERGEFIELD InvoiceItem.ExtendedPrice \* MERGEFORMAT}​ = 0 "FREE" "" \* MERGEFORMAT }

You must insert a space before and after the operator. Operators include =, >, and =<.

Last modified
19:23, 4 Mar 2015



(not set)