- 3 minutes to read

Formula - Min

The min function, one of the Math functions in the Formula plugin for Search Field Expressions, returns the lowest numeric value in the content.

Syntax

min(content [, unique])

Parameters

Parameter Required Description
content ✅ Yes The numeric values to compare: body, context, or another Formula function such as xPath, jsonPath, or csv.
unique ❌ No Unquoted true or false; default true 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 lowest numeric value in content.
  • Values are compared as numbers, so 8 is lower than 42 even when the values are JSON strings (see Example 2).

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

Examples

Example 1: Lowest order amount in an XML message

Input

Message Body:

<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
  <Order>
    <Id>1337</Id>
    <Amount>666</Amount>
    <City>Grums</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
  <Order>
    <Id>1338</Id>
    <Amount>42</Amount>
    <City>Karlstad</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
</ns0:Orders>

Formula

min(xPath('Orders/Order/Amount', body))

Result

42

xPath extracts the amounts 666 and 42; the lowest is 42.

Test Expression tab: min(xPath('Orders/Order/Amount', body)) on orders with amounts 666 and 42 returns 42
The amounts are compared as numbers, so 42 is lower than 666.

Example 2: Lowest value extracted from JSON

Input

Message Body:

{a:[{b:'1337'},{b:'8'},{b:'42'}]}

Formula

min(jsonPath('a[*].b', body))

Result

8

Test Expression with Min of jsonpath over every b in the array a, on a JSON array, returning 8
jsonPath extracts 1337, 8, and 42; the lowest is 8. The screenshot writes the function name as Min; names are case-insensitive.

Example 3: Lowest value in a CSV column stored in message context

Input

Message Context:

Key Value
Ids the CSV text below
Header#Content-Type Application/XML
"face","suit","value"
"king","spades","13"
"queen","spades2","12"
#"jack","spades3","666"
"ten","spades4","10"

Formula

min(csv(1, ',', 2, '#', context('Ids')))

Result

10

Test Expression with min(csv(1,',',2,'#',context('Ids'))) on CSV text in the context key Ids, returning 10
csv skips the header row, reads column 2 (the value column, counted from 0), and ignores the row that starts with #; the lowest of 13, 12, and 10 is 10.

Next Steps