# Built-In TERR Expression Functions in Spotfire

In the Spotfire Custom Expressions or Insert Calculated Column dialog box, from the Function list, you can select one of the built-in TERR expression functions provided for advanced statistical analysis.

Each function invokes the TERR engine. The results depend on the expression function you select.

- For nonaggregated functions, the TERR script should set the variable `output` to a vector or a one-column data frame, which is the same length as the input column(s), of the specified TERR data type. Spotfire converts the data type to the corresponding Spotfire data type.
- For aggregated functions, the TERR script should set the variable `output` to a scalar value of the specified TERR data type, which Spotfire converts to the corresponding Spotfire data type. The TERR script is called once for each group of data to be aggregated. No special handling for aggregation is necessary in your TERR script.

Spotfire and TERR use the following naming convention for defining expression functions.

Expression function component | Description | Example
--- | --- | ---
`TERR_<SpotfireDataType>` or `TERRAggregation_<SpotfireDataType>` | The built-in expression function. | `TERR_Real("output <- input1/input2", [Mileage], [Fuel])` The TERR returned value (specified by `output` is a vector of data type `numeric`, which Spotfire converts to a column of the Spotfire data type Real.
`input1`, `input2`, `input3`... `inputN` `[Colname]`, `[Colname]`, `[Colname]`, `[Colname]` | Each input (`inputN`) is a parameter that is passed in to the TERR expression function, and that corresponds to a column name (Colname) in the same numerical order. The column names corresponding to the inputs are added as the last component of the expression, immediately after the calculation's closing quotation marks and comma, and immediately before the closing parenthesis. Each column name is enclosed in square brackets. Column names are separated by commas. | `TERR_Real("output <- input1/input2", [Mileage], [Fuel])` `[Mileage]` corresponds to `input1`. `[Fuel]` corresponds to `input2`. The calculation specifies that, for each row, the value in the column `Mileage` is divided by the value for the column `Fuel`.
`output` | The returned value of the calculation in TERR. It can be added to the Spotfire visualization as a column or a single aggregated value. | `TERR_Real("output <- input1/input2", [Mileage], [Fuel])` `output` represents the column of `Real` values returned containing the calculation for each row of the mileage divided by the fuel.

Select one of the topics for the available built-in expression functions to learn more.