Tinderbox v10 Icon

avg_if(scope, condition, expressionStr)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Data Type Returned: 

Operator First Added: 

Operator in Current Baseline: 

Operator Last Altered: 

Operator Uses Scoped Arguments: 

Operator Has Conditional Arguments: 

 Function  [other Function type actions]

 Conditional Group  [operators of similar scope]

 Mathematical  [other Mathematical operators]

 Number [about Number data type]

 v4.6.0

 Baseline

 As at baseline

 [More on scoped arguments in Action Code]

 [More on conditional operator arguments]


avg_if(scope, condition, expressionStr)

The function avg_if() computes the arithmetic mean of a list of the values of scope items, and returns a List-type data. Each of the items in scope (defining scope) is tested and ignored it if it fails to meet condition, otherwise items supply a value to then adding the value of each list item evaluated using the designated expressionStr. Be aware that the per-item value might be a literal value, an attribute value, or a value/string of content based on that item's expressionStr.

For a related, less focussed, operator see avg().

This computes the arithmetic mean of the value of a expressionStr in a group, as filtered by a condition expression. See avg() for a for a related non-conditional operator.

scope describes the note(s) to be examined and may be any group designator including a find() query.

condition is action code forming a valid conditional query test, i.e. it equates to true when matched. Some query-style operators terms may allow use of regular expressions.

expressionStr may be any valid expression, but will usually be a reference to an attribute; short form Boolean attribute expressions are acceptable.

For example:

$MyNumber = avg_if(children(/Catalog),$Price!=0,$Price); 

sets $MyNumber to the average price of all the items in Catalog, ignoring any items that have a price of 0.


See also—notes linking to here: