---
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.
---

# <i class="fal fa-function" aria-hidden="true"></i> 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`.*  

## <i class="fal fa-code" aria-hidden="true"></i> 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. <sup><span class="nodinite-new-badge">New 7.12</span></sup> 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][].

## <i class="fal fa-list-ol" aria-hidden="true"></i> 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.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> 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`.

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-hashtag" aria-hidden="true"></i> [count][]  
* <i class="fal fa-text-width" aria-hidden="true"></i> [length][]  
* <i class="fal fa-arrow-up-wide-short" aria-hidden="true"></i> [max][]  
* <i class="fal fa-arrow-down-short-wide" aria-hidden="true"></i> [min][]  
* <i class="fal fa-circle-half-stroke" aria-hidden="true"></i> [round][]  
* <i class="fal fa-plus" aria-hidden="true"></i> [sum][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[count]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/count/
[ex1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/average_Example1.png
[ex2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/average_Example2.png
[ex3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/Formula_MinMaxAverage.gif
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[length]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/length/
[max]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/max/
[min]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/min/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[round]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/round/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[sum]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/sum/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[xPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/