Data Measures and Calculated Measures
Data measures help you aggregate data from a dataset column. For instance, you can create a data measure to count unique values in a column. Calculated measures allow you to do basic math using column values, other measures, or expressions. For example, you can create a calculated measure to find the difference between two other measures.
For more information about measures in SuiteAnalytics Workbook, see Calculated Measures.
You can create a data measure using workbook.createDataMeasure(options). This method creates a workbook.DataMeasure object. To create a data measure, you'll need to provide these 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.
You can also add a label
parameter to your data measure.
var myDataMeasure = workbook.createDataMeasure({
aggregation: workbook.Aggregation.SUM,
expressions: [dataset.getExpressionFromColumn({
alias: 'MyColumn'
})],
label: 'My Sum'
});
You can create a calculated measure using workbook.createCalculatedMeasure(options). This method creates a workbook.CalculatedMeasure object. To create a calculated measure, you only need to provide the options.expression
parameter, which represents the expression for the calculated measure. Create the expression using workbook.createExpression(options) and use 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.
You can also add a label
parameter to your calculated measure.
var myCalculatedMeasure = workbook.createCalculatedMeasure({
expression: workbook.createExpression({
functionId: workbook.ExpressionType.MINUS,
parameters: {
operand1: myFirstOperandExpression,
operand2: mySecondOperandExpression
}
}),
label: 'My Calculated Measure'
});