This version is out of date, covering development from v9.5.0 to v9.7.3. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

avg_if(scope, condition, expressionStr)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

Operator Uses Scoped Arguments: 

Operator Has Conditional 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.