Tinderbox v9 Icon

sum_if(scope, condition, expressionStr)

Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

Operator Uses Regular Expressions: 

Operator Uses Scoped Arguments: 

Operator Has Conditional Arguments: 

Operator Has Newer Dot-Operator Variant: 

sum_if(scope, condition, expressionStr)

This computes the Number sum of every expressionStr value in each scope item (defining scope), as filtered by a condition expression. See sum() for a related non-conditional operator.

scope describes the notes to be examined and may be any group designator including a find() query. sum_if() omits notes for which $Searchable is false.

In addition, where may be argument that designates a particular (single) note other than this.

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 can be an expression, but is typically a Number-attribute value or a List/Set holding a list of numbers. It can also be a literal number 1, i.e. if the test is true from that item then add one to the retuned value of sum_if().

For example,

$MyNumber = sum_if(children,$Prototype=="p_Problem",1); 

sums the number of children of the current note whose prototype is 'p_Prototype'. If tested value is a string with spaces, e.g. "p Prototype" vs. "p_Prototype" then use double quotes around the value.

The newer count_if() offers a more intuitive method of counting matches rather than the value of matched items.