---
title: Formula avg – Average Numeric Values in Nodinite Search Field Expressions
description: The avg function in the Nodinite Formula plugin returns the average of the numeric values in the content. Syntax, the unique parameter, and examples with xPath and jsonPath.
---

# :fa-function: 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.

![Lowest, highest, and average line total of an order with min, max, and avg, animated walkthrough (7.12)][ex3]  
*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`.*  

## :fa-code: Syntax

```text
avg(content [, unique])
```

### Parameters

| Parameter | Required | Description |
| --- | --- | --- |
| `content` | ✅ Yes | The numeric values to average: [body][], [context][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

* 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.9333333333333333333333333` for 1022.80 / 3. :new7.12: Wrap it in [round][] to shorten it: `round(avg(...), 2)` returns `340.93`.
* When `content` holds no numeric value, `avg` returns nothing.

Quoting, nesting, and how `content` is resolved are described in the [Formula language rules][].

## :fa-list-ol: Examples

### Example 1: Average the order amounts in an XML message

#### Input

Message Body:

```xml
<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

```text
avg(xPath('Orders/Order/Amount', body))
```

#### Result

```text
3
```

[xPath][] extracts the amounts `4` and `2`; their average is `3`.

![Test Expression tab: avg(xPath('Orders/Order/Amount', body)) on two orders with amounts 4 and 2 returns 3 (7.12)][ex1]  
*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

#### Input

Message Body:

```json
{"a":[{"b":1},{"b":2},{"b":6}]}
```

#### Formula

```text
avg(jsonPath('a[*].b', body))
```

#### Result

```text
3
```

[jsonPath][] extracts `1`, `2`, and `6`; their average is `3`.

![Test Expression tab: avg of jsonPath over every b in the array a, on the JSON values 1, 2, and 6, returns 3 (7.12)][ex2]  
*`a[*].b` selects `b` in every element of the array `a`; the result is one number, not three.*  

## :fa-circle-info: Notes

* By default every occurrence counts: lines of `100`, `100`, and `400` average `200`. With `avg(..., true)` identical values count once, so the average is `(100 + 400) / 2 = 250`.

## :fa-hand-point-right: Next Steps

* :fa-magnifying-glass-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-hard-drive: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-hashtag: [count][]  
* :fa-text-width: [length][]  
* :fa-arrow-up-wide-short: [max][]  
* :fa-arrow-down-short-wide: [min][]  
* :fa-circle-half-stroke: [round][]  
* :fa-plus: [sum][]  
* :fa-function: [Formula][]  
* :fa-scroll: [Formula language rules][]  
* :fa-puzzle-piece: [Search Field Expressions][]  

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[body]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/body.md
[Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/context.md
[count]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/count.md
[ex1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/average_Example1.png
[ex2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/average_Example2.png
[ex3]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/Formula_MinMaxAverage.gif
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula language rules]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#fa-scroll-formula-language-rules
[jsonPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/jsonPath.md
[length]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/length.md
[max]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/max.md
[min]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/min.md
[Order-to-Cash demo]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data.md
[round]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/round.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[sum]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Math/sum.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[xPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath.md