OLAP Aggregate Queries : Metric Parameter : Metric Functions

Metric Functions
In it’s basic form, the metric parameter is a comma-separated list of metric functions. Each function performs a statistical calculation on a scalar or link field. The general syntax of a metric function is:
function(field)
Where function is a metric function name and field defines what the metric function is computed on. The field must be a scalar or link defined in the application’s schema. It can belong to the perspective table, or it can be a path to a field linked to the perspective table (e.g., DirectReports.Name).
If the metric function parameter is a field path with a reflexive link, the transitive operator can be used. Example:
COUNT=(DirectReports^)
This function counts all DirectReports link values for each perspective object (i.e., all employees in the org chart reporting to each person). Scalar fields of transitively-linked objects can also be used as the metric function’s parameter. For example:
MAX(Manager^.FirstName)
This function finds the maximum FirstName (highest, alphabetically) of all managers “up” the org chart for each perspective object. For more information on the transitive operator, see the section Transitive Function.
The supported metric functions are summarized below:
COUNT(field): Counts the values for the specified field. If the field is multi-valued with respect to the perspective object, all values are counted for each selected object. For example, COUNT(Tags) tallies all Tags values of all objects. The COUNT function also allows the special value “*”, which counts the selected objects in the perspective table regardless of any fields. That is, COUNT(*) counts objects instead of values.
DISTINCT(field): This metric is similar to COUNT except that it totals unique values for the given field. For example, COUNT(Size) finds the total number of values of the Size field, whereas DISTINCT(Size) finds the number of unique Size values.
SUM(field): Sums the non-null values for the given numeric field. The field’s type must be integer, long, float, or double.
AVERAGE(field): Computes the average value for the given field, which must be integer, long, float, double, or timestamp. Note that the AVERAGE function uses SQL null-elimination semantics. This means that objects for which the metric field does not have a value are not considered for computation even though the object itself was selected. As an example, consider an aggregate query that computes AVERAGE(foo) for four selected objects, whose value for foo are 2, 4, 6, and null. The value computed will be 4 ((2+4+6)/3) not 3 ((2+4+6+0)/4) because the object with the null field is eliminated from the computation.
MIN(field): Computes the minimum value for the given field. For scalar fields, MIN computes the lowest value found based on the field type’s natural order. For link fields, MIN computes the lowest object ID found in the link field’s values based on the string form of the object ID.
MAX(field): Computes the maximum value for the given field, which must be a predefined scalar or link field.
MAXCOUNT(field): This function computes the maximum cardinality of the given scalar or link field. For example, for the Message table, MAXCOUNT(ExternalRecipients) returns the highest number of ExternalRecipients values found for selected objects.
MINCOUNT(field): This function computes the minimum cardinality of the given field. If any selected objects have no value for the given field, the result will be 0.
When applied to a single-valued field, the result of both MINCOUNT and MAXCOUNT will be either 0 or 1.
Example metric functions are shown below:
COUNT(*)
DISTINCT(Tags)
MAX(Sender.Person.LastName)
AVERAGE(Size)
MAXCOUNT(Sender.Person.DirectReports)