How to Add Calculated Columns With TERR

I know I said I would revert back to IronPython posts. But, I had to do a bit of TERR work this week that I thought users might find helpful. Now, my use case was fairly complex, but the root of it was simply adding calculated columns to a table in TERR by applying the “within” R function.

Before I get started, note that this is a simplified example. You may look at this demonstration and wonder why I didn’t use a calculated column. I had good reasons for performing this task in TERR. To demonstrate the “within” function, I created a simpler example.

Original Table

Here is my original table. I need to add a BOE calculation to this table.

Original table

Using the Within Function

Here is my TERR script. The script performs three steps.

  1. Create an object called mytable that is equal to my input parameter.
  2. Create a new calculated column called BOE. Note, I lead with the table/object name and denote the column with “$”.
  3. Build a new object called mytable2. The within function adds the new column to mytable. Mytable2 is my output parameter.
TERR script

Parameters

After writing the script, I setup my input and output parameters.

I only have one input parameter (Type = table).

Input parameters

I have one output parameter (Type = table) called mytable2.

Output parameters

With the script, input parameters, and output parameters complete, I can run the data function and map my columns to the parameters. This was the result.

Final Output

The “within” function allows the user to easily append an existing table.

Now, you know how to add calculated columns with TERR.

Related Links

If you are unfamiliar with TERR data functions, check out this post on TERR basics. If you would like a simple data function to test your skills, try this pass thru data function.

Spotfire Version

Content created with Spotfire 10.2.

1 thought on “How to Add Calculated Columns With TERR”

  1. Pingback: Find Unique Values with TERR » The Analytics Corner

Leave a Reply

Your email address will not be published. Required fields are marked *