Formula - Average (avg)
Section titled “ Formula - Average (avg)”The avg function, one of the Math functions in the Formula plugin for Search Field Expressions, returns the average of the numeric values in the content.

Animated walkthrough: on the Order Entry XML of order ORD-10011 in the Order-to-Cash demo, with the line totals 399.80, 498.00, and 125.00, min returns 125.00, max returns 498.00, and avg returns 340.9333333333333333333333333, which is 1022.80 / 3, not rounded; use round(avg(...), 2) for 340.93.
Syntax
Section titled “ Syntax”avg(content [, unique])Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
content |
✅ Yes | The numeric values to average: body, context, or another Formula function such as xPath or jsonPath. |
unique |
❌ No | Unquoted true or false; default false for this function. false: a value that appears several times counts every time. true: identical values count once. Values are compared as text, so 100 and 100.00 are different values. A quoted 'true' is an error. |
Returns
Section titled “Returns”- One number: the average (mean) of the numeric values in
content. - The average isn't rounded: it keeps up to 28 decimals, such as
340.9333333333333333333333333for 1022.80 / 3. New 7.12 Wrap it in round to shorten it:round(avg(...), 2)returns340.93. - When
contentholds no numeric value,avgreturns nothing.
Quoting, nesting, and how content is resolved are described in the Formula language rules.
Examples
Section titled “ Examples”Example 1: Average the order amounts in an XML message
Section titled “Example 1: Average the order amounts in an XML message”Message Body:
<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0"> <Order> <Id>1337</Id> <Amount>4</Amount> <City>New York</City> <Partner>QWNtZQ==</Partner> </Order> <Order> <Id>1338</Id> <Amount>2</Amount> <City>Paris</City> <Partner>QWNtZQ==</Partner> </Order></ns0:Orders>Formula
Section titled “Formula”avg(xPath('Orders/Order/Amount', body))Result
Section titled “Result”3xPath extracts the amounts 4 and 2; their average is 3.

The namespace prefix ns0: doesn't need to be part of the XPath; Orders/Order/Amount matches it.
Example 2: Average numeric values extracted from JSON
Section titled “Example 2: Average numeric values extracted from JSON”Message Body:
{"a":[{"b":1},{"b":2},{"b":6}]}Formula
Section titled “Formula”avg(jsonPath('a[*].b', body))Result
Section titled “Result”3jsonPath extracts 1, 2, and 6; their average is 3.

a[*].b selects b in every element of the array a; the result is one number, not three.
- By default every occurrence counts: lines of
100,100, and400average200. Withavg(..., true)identical values count once, so the average is(100 + 400) / 2 = 250.