CALC

CALC, CALCULATE

Top  Previous  Next

 

The CALC keyword prefixes an I-type field name or an evaluated expression and causes the calculation to be performed on the total lines, possibly using accumulated values from the detail lines.

 

 

Format

 

CALC field

 

where

 

fieldis the I-type field or expression for which the calculation is to be performed.

 

 

The CALC keyword is normally used 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.

 

The CALC keyword can be used for any other expression to be evaluated at breakpoints and at the end of the report. See the BREAK.SUP keyword for an example of using this with the X breakpoint control option.

 

 

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.