Array builtins

Array builtins operate on arrays or arrayed expressions. Use these builtins to find the sum, the standard deviation, or the mean across dimensions of arrayed variables. Many of these functions work on array ranges, and there is in-depth discussion of this in Specialized Array Manipulation.

Note MIN, MAX, and MEAN, when called with more than one argument, operate on non-arrayed expressions.

The array builtins can be applied to either an arrayed variable or an expression. Some can also be applied to conveyors and queues to deal with the elements within the stock.

Note Not all of the builtin functions can be used in Array expressions. You can't use any builtin that has a value depending on previous results (this includes the Delay builtins, Data builtins and Random builtins ). You also can't use any other array or array operation builtins in the expression (it is not possible to nest array builtins.)

When an array builtin is applied to an expression, care must be taken to ensure that the intended dimensions are being reduced as expected.

 

This section describes the following builtins:

MAX(<array or expression>)

When called on an array takes the maximum across elements of the array slice. when called with 2 arguments it will take the maximum of the two arguments and does not allow array slices.

MEAN(<array or expression>)

The MEAN builtin calculates the arithmetic mean across the elements in <array or expression> when called with 1 argument or across the arguments when called with more than one argument. The calculation is defined as the sum of the elements, divided by the number of elements in the array or the sum of the arguments divided by the number of arguments.

To report the mean across a subset of the dimensions of the arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's mean in either an arrayed or a non-arrayed converter or flow.

Examples:

Average Salary for Employees = MEAN(Salaries)

Average Salary for Employees in Boston = MEAN(Salaries[Boston,*])

Average Salary for Labor Groups 1 to 3 = MEAN(Salaries[*,1:3])

MIN(<array or expression>)

When called on an array takes the minimum across elements of the array slice. when called with 2 arguments it will take the minimum of the two arguments and does not allow array slices.

PROD(<array or expression>)

The PROD builtin calculates the product of all the elements in the array or expression.

To report product across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension, or a range specified (min:max) to report part of the array. You can use the arrayed variable's product in either an arrayed or a non-arrayed variable.

Example:

Interest_Factor[Year] = (1.0 + Interest_Rate[Year])

Compounded_Interest_to_Year[Year] = principal * PROD(Interest_Factor[1:year])

SELF

Use the SELF builtin in conjunction with the SIZE, PREVIOUS, and ENDVAL builtins to refer to the current variable.

You can also use SELF[Dim1-1,Dim2] and similar forms to refer to different elements in an array. For example a variable arrayed by position could have the equation

IF position = 1 THEN 0 ELSE SELF[position-1] + width[position-1]

which would add the width of each successive position to compute the next position.

SIZE(<array or dimension>)

The SIZE builtin gives the number of elements in the array or dimension.

Note: You can also use the SIZE builtin to report the length of a queue.

To get information on the array holding the equation, use the SELF builtin.

Examples:

SIZE(Location) gives the number of elements in the dimension Location.

SIZE(sales) where sales is arrayed by location gives the number of elements in the dimension Location.

SIZE(SELF) gives the number of elements in this array.

SIZE(SELF[*, 1]) gives the size of the first dimension of this array.

SIZE(SELF[1, *]) gives the size of the second dimension of this array.

SIZE (<queue>) returns the total number of elements contained in the specified queue-type discrete stock.

SIZE (<conveyor>) returns the total number of slots contained in the specified conveyor-type discrete stock.

STDDEV(<array or expression>)

The STDDEV builtin calculates standard deviation for all the elements in the array or expression.

To report the standard deviation across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's standard deviation in either an arrayed or a non-arrayed converter or flow.

Example:

Standard Deviation of Salary in Boston= STDDEV(Salaries[Boston,*])

SUM(<array or expression>)

The SUM builtin calculates the sum of all the elements in the array or expression.

To report the sum across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's sum in either an arrayed or a non-arrayed converter or flow.

Example:

Total Salary for Employees in Boston = SUM(Salaries[Boston,*])

Concept Link IconSee Also