Data Measures and Calculated Measures
Data measures let you perform simple aggregations on the data in a column in the underlying dataset. For example, you can define a data measure that counts the number of distinct values that appear in a column. Calculated measures let you perform simple arithmetic operations based on the values in a column or using another measure or expression. For example, you can define a calculated measure that calculates the difference between the values of two other measures.
For more information about measures in SuiteAnalytics Workbook, see Calculated Measures.
To create a data measure, use workbook.createDataMeasure(options). This method creates a workbook.DataMeasure object. When you use this method, you must provide the following parameters:
-
aggregation
– The type of aggregation to use for the data measure. Use values from the workbook.Aggregation enum. -
expression
orexpressions
– The expression (or expressions) for the data measure. Useexpression
for single-expression measures, and useexpressions
for multiple-expression measures. Use Dataset.getExpressionFromColumn(options) to get an expression that represents a column in the underlying dataset, or use workbook.createExpression(options) to create a custom expression. For more information, see Expressions.
Optionally, you can provide a label
parameter for the data measure.
var myDataMeasure = workbook.createDataMeasure({
aggregation: workbook.Aggregation.SUM,
expressions: [dataset.getExpressionFromColumn({
alias: 'MyColumn'
})],
label: 'My Sum'
});
To create a calculated measure, use workbook.createCalculatedMeasure(options). This method creates a workbook.CalculatedMeasure object. When you use this method, only the options.expression
parameter is required, and it represents the expression for the calculated measure. Use workbook.createExpression(options) to create this expression, and use the functions from the workbook.ExpressionType enum.
For the top-level expression that you use in a calculated measure, only the PLUS
, MINUS
, DIVIDE
, and MULTIPLY
operands are valid. However, you can use other operands in expressions for each parameter in the top-level calculated measure.
Optionally, you can provide a label
parameter for the calculated measure.
var myCalculatedMeasure = workbook.createCalculatedMeasure({
expression: workbook.createExpression({
functionId: workbook.ExpressionType.MINUS,
parameters: {
operand1: myFirstOperandExpression,
operand2: mySecondOperandExpression
}
}),
label: 'My Calculated Measure'
});