CALCULATE command
Calculates the value of one or more expressions.
Syntax
CALCULATE expression <AS result_label> <,...n>
Parameters
Name | Description |
---|---|
expression |
The expression to calculate. The expression can be any of the four types:
Separate multiple expressions with a comma: CALCULATE 4.7 * 18.5, 1 + 2, "a" + "b" |
AS result_label optional |
The name of the result when displayed on screen and in the Analytics command log. result_label must be a quoted string or a valid character expression. If omitted, the expression being calculated is used as the result name. |
Examples
Performing a simple calculation
You use CALCULATE to multiply 4.70 by 18.50, returning the result 86.95:
CALCULATE 4.70 * 18.50
Naming the results of a calculation
You use CALCULATE to derive the gross margin for the currently selected record using previously defined fields for sale price and unit cost:
CALCULATE Sale_price - Unit_cost AS "Margin"
The result is identified on screen, and in the log, as "Margin".
Remarks
How it works
CALCULATE provides the functionality of a calculator combined with access to Analytics functions, variables, and the data in the currently selected record.
Command output
Depending on where you run CALCULATE, the results are output to different locations:
- From the command line the result is displayed on screen
- From within a script the result is recorded in the log
The result_label value is not a variable that you can use in a script. It is only used to identify the calculation on screen or in the log.
Number of decimal places in output
In a numeric calculation, the result has as many decimal places as the expression component with the greatest number of decimal places.
Returns 1:
CALCULATE 365/52/7
Returns 1.0027:
CALCULATE 365.0000/52/7
Working with table input
If the expression contains a field value, the table the field belongs to must be open. You can use the FIND, SEEK, or LOCATE commands to move to the record to be analyzed by CALCULATE.