This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions pageOpens in a new window (login required).

# CALC clause

Returns the calculated value for a field.

## Synopsis

```CALC field
```

## Description

The CALC clause calculates the value for an I-type numeric field. CALC calculates to two decimal places. Leading and trailing zeros are suppressed.

Multiple CMQL clauses may be specified in any order. The order of application of CMQL clauses is always the same. The CALC clause is applied after the WITH clause, the SAMPLED clause (if present), and the SAMPLE clause (if present).

### Examples

The following MultiValue Basic example creates an I-type field IPCT the value of which is calculated from the values of the fields PRICE and DSCPRICE:

```0001 EXECUTE 'CREATE-FILE MYTESTFILE 1 1' CAPTURING STUFF
0005 OPEN 'DICT','MYTESTFILE' TO DICT.FP ELSE ABORT
0006 OPEN 'MYTESTFILE' TO FP ELSE ABORT
0007 WRITE '100':@AM:'50' ON FP,3
0008 WRITE '197':@AM:'175' ON FP,2
0009 WRITE '203':@AM:'180' ON FP,1
0010
0011 WRITE 'D':@AM:1:@AM:@AM:'PRICE':@AM:'10R' ON DICT.FP,'PRICE'
0012 WRITE 'D':@AM:2:@AM:@AM:'DSCPRICE':@AM:'10R' ON DICT.FP,'DSCPRICE'
0013 WRITE 'I':@AM:\(TOTAL(PRICE-DSCPRICE))*100/TOTAL(PRICE)\:@AM:'MR20':@AM:'IPCT':@AM:'10R' ON DICT.FP,'IPCT' ```
`LIST MYTESTFILE TOTAL PRICE TOTAL DSCPRICE CALC IPCT`
FeedbackOpens in a new window