CALC, CALCULATE |
![]() ![]() ![]() |
The CALC keyword prefixes an I-type field name or an evaluated expression and causes the calculation to be performed on the total lines using accumulated values from the detail lines.
Format
CALC field
where
The CALC keyword works in conjunction with the I-type TOTAL() function. During detail lines, the TOTAL() function accumulates values which are then used on the subtotal and grand total lines to calculate the value in the column to which the CALC keyword applies.
Example
We have a file which includes a calculated PROFIT item defined as
100 * (SELL - COST) / COST
The command
LIST PARTS AVG COST AVG SELL AVG PROFIT
This might produce a report such as that below
LIST PARTS AVG COST AVG SELL AVG PROFIT Part Cost. Sell. Profit% 101 10.00 13.00 30.00 102 15.00 18.00 20.00 103 14.00 17.00 21.43 ===== ===== ===== 13.00 16.00 23.81 3 records listed.
The average profit figure (23.81) is the average of the figures in the column above it. Perhaps what we really want to show is the percentage profit selling for 16.00 something that cost us 13.00 (the average cost and selling prices). To do this, the PROFIT expression is changed to 100 * (TOTAL(SELL) - TOTAL(COST)) / TOTAL(COST) or, more simply, 100 * TOTAL(SELL - COST) / TOTAL(COST)
The command LIST PARTS AVG COST AVG SELL CALC PROFIT now produces
LIST PARTS AVG COST AVG SELL CALC PROFIT Part Cost. Sell. Profit% 101 10.00 13.00 30.00 102 15.00 18.00 20.00 103 14.00 17.00 21.43 ===== ===== ===== 13.00 16.00 23.08 3 records listed. |