Formula - Average (avg)
Easily calculate the average of values from your data using the average (avg) Formula in Nodinite. This page provides clear, real-world examples with a new, easy-to-read layout that separates input, formula, and result.
✅ Instantly compute averages from message body, Context, or nested formulas ✅ Use with XML, JSON, or plain text data ✅ Boost your integration insights with unique, reliable results
🎯 Design Note: The avg()
function calculates the mean of unique values extracted from your data.
What does the average (avg) formula do?
The avg()
formula calculates the average (mean) of unique values extracted from your data. Use it to analyze message payloads, context values, or results from other formulas in your log views and search fields.
Examples
Below are practical examples showing exactly what input is used, the formula expression, and the resulting output.
- From Message Body:
avg(body)
- From Message Context:
avg(context('MessageContextKey'))
- From Nested Formula:
avg(SomeOtherFormula(Content))
Example 1: XML Message Body
Input
<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 Expression
avg(xpath('Orders/Order/Amount', body))
Result
3
Example 2: Plain Text Body
Input
Nodinite
Formula Expression
avg(body)
Result
1
The result is 1 because the message body contains a single value.
Example 3: Message Context Value
Input
Nodinite
Formula Expression
avg(context('amount'))
Result
1
The result is 1 because the context value for 'amount' is a single value.
Example 4: JSON with Nested Formula
Input
{"a":[{"b":1},{"b":2},{"b":6}]}
Formula Expression
avg(jsonpath('a[*].b', body))
Result
3
The result is 3 because the average of 1, 2, and 6 is 3.
Features
- Calculate the average of extracted values from any Content
- Works with XML, JSON, plain text, or any valid formula plugin
- Returns the average of unique values only
- Ideal for integration analytics and data validation in Nodinite
Important
This plugin loads the entire message into RAM. For best performance, use it only on small messages.
How to use the average (avg) formula
Syntax
- From Message Body:
avg(body)
- From Message Context:
avg(context('MessageContextKey'))
- From Nested Formula:
avg(SomeOtherFormula(Content))
Next step
Related Topics
- Expression Type Plugins are used in Search Fields
- What are Search Fields?
- What are Search Field Expressions?
- What are Message Types?
- What are Log Views?
- Other Math formulas: count, length, max, min, sum