Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Operator Has Newer Dot-Operator Variant:
Function [other Function type actions]
List [operators of similar scope]
Mathematical [other Mathematical operators]
Number [about Number data type]
v4.0.0
Baseline
As at baseline
Yes
max(numberList)
The max() operator returns the largest item in a list or the values or a List or Set data type attribute. As it operates off a list it may be more convenient to use the newer list.max() chained operator.
Both the operators max() and min() use lexical comparison in most cases, but numeric comparison if the context is numeric (i.e. the reference is a Number-type attribute) and/or all list items are numbers. Thus:
$Width=max("1;100;2");
Since "Width" is numeric, max() will be return 100.
$Name=max("1;100;2");
Since the attribute "Name" is a string, max() will return 2.
If without a list, create one on the fly using list(), collect() or collect_if():
$MyMax = max(list($DateA,$DateB,$DateC));
$MyMax = max(collect(descendants,$Modified));
$MyMax = max(collect_if(all,$MyNum>0,$MyNum));
This allows export via ^value^:
^value(max(collect(descendants,$Modified)))^
To use max() with a list of expressions, use list():
Works: $MyNumber = max(list(4+2,9+6));
(output: 15)
For more complex examples, where list items are action code expressions, it may be necessary to use eval() to wrap each list item expression e.g. list(eval(expressionA),eval(expressionB))
.
Using lists of dates
When using Date-type data bear in mind that the defaults for an unset Date attribute is "never
" and that "never" is treated as sorting always before (i.e. less than) any set date. So to use min() with dates, filter out the unset values, whereas with max() it is not needed:
$MyMax = max(collect_if(descendants,$Modified));
$MyMin = min(collect_if(descendants,($Modified!="never"),$Modified));
See also—notes linking to here: