 Skip to main content

# Use aggregates and expressions in a find and replace tax rule

Use aggregates and expressions to create a more complex find and replace tax rule. Aggregates and expressions can identify variables, compare values, or apply functions to your transaction data. This makes it possible to swap address values under unique circumstances or change taxability based on a specific threshold (such as Ireland's two-thirds rule).

## How aggregates work

Aggregates identify specific transaction fields in your data. Once defined, aggregates can be used as variables in expressions.

For example, create an aggregate to add up the line amounts of all transaction lines that have a tax code of P0000000:

1. In the Definition fields, include the following items:
• Name: TotalByTaxCode
• Aggregate: Sum
• Aggregate Field: Line.Amount
2. In the When fields, set Condition 1 to be TaxCode > equals any of these > P0000000

Use aggregates in the Expressions and Variables section by entering your aggregate name enclosed in double brackets, such as {{TotalByTaxCode}}. See the next section for more examples.

## How expressions and variables work

Add an expression to define a single variable or create a formula. Defined expressions may be used as conditions for find and replace operations.

Expression fields support integers, defined variables, or mathematical operators like / * and >.

For example, create expressions to compare a numerical variable like 100 to the TotalByTaxCode aggregate created in the previous example.

1. Expression 1: This establishes the TotalAmount100 variable and defines it as 100.
• Name: TotalAmount100
• Aggregate: 100
2. Expression 2: This is a formula that compares the sum of all lines with tax code P0000000 (TotalByTaxCode in the previous example) to 100 (TotalAmount100).
• Name: Comparison
• Aggregate: {{TotalByTaxCode}} > {{TotalAmount100}}

Either of these expressions can be used as conditions in the When section by entering the expression name surrounded by brackets, like this: {{Comparison}}.