Functions and Variables Reference for Calculations

This is the currently supported list of functions and variables for Calculations in Coggle diagrams. If there's something missing that you'd find useful, let us know at hello@coggle.it  – we're always to interested to hear about the ways you use Coggle and how we can make it better!


Automatic Variables

Variables must always be in uppercase letters. Most variables resolve to an array of multiple values.

When a variable is used in an additive expression, like =(1 + CHILDREN), or used on its own =(LEAVES) all of its values are automatically summed: the separate values are never displayed in a result.

CHILDREN              The values of all of the immediate children of this item (items connected by a single branch pointing away from this item)
LEAVES             

The values of all of the items that are descended from this item (with branches pointing from this item to them), only if they have no children of their own (i.e. not including intermediate items.

This is the most useful variable for creating budget-like totals, as intermediate totals can be added without affecting the total.

PARENT              The value of the calculation in the parent of this item (connected with a branch pointing from the parent item to this one). If there is not exactly one calculation in this item's parents, this variable produces an error.
PARENTS              The values of all of the parents of this item (connected with a branch pointing from the parent item to this one).
ROOTS              The opposite of leaves - all the values in items with no parents (no branches pointing in to them) which this item is connected to by following branches.

💡Tip: In addition to these automatic variables which reference connected items, you can give the result of any calculation a name. To create a variable called LEAF_COUNT you could do: LEAF_COUNT=(COUNT(LEAVES)), and then to use it: This map has =(LEAF_COUNT) leaves.

Functions

Functions must always be uppercase, and always use brackets around their arguments. Function arguments are separated by a comma.

An array variable may be used as a single argument, for example: =(MAX(6, LEAVES))will return 6 if 6 is greater than any of the values in leaves, otherwise the maximum value in a leaf calculation.

Functions may be composed, for example =(MIN(COUNT(CHILDREN), 5))will return the number calculations in child items, up to at most 5.

ABS        The absolute magnitude of a value.
AVERAGE        The average (mean) of the values. Produces an error if there are no values.
COUNT              The number of values passed.
EXP              The exponential function.
LN              Natural logarithm.
MAX              The maximum (or most positive) value passed.
MIN             The minimum (or most negative) value passed.
RAND     A random number between 0 and 1. This will change each time the diagram is loaded, or the calculation edited. Accepts 0 values.
RANDBETWEEN     A random number between the first and second values passed . This will change each time the diagram is loaded, or the calculation edited. Accepts exactly 2 values.
STDEV.S        The standard deviation, based on a sample of values. Produces an error if there are less than two values.
SUM             The sum of the values passed.
SUMSQ              The sum of the values, each squared.  Useful for some statistical calculations.
SQRT              The square root of the value. Accepts exactly one value only.

Randomness

Random functions (RAND   , RANDBETWEEN), will return a different value each time the diagram is loaded. This means that different people viewing the same diagram are likely to see different numbers. Downloading a PDF or PNG of the diagram will also display different numbers.