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.
Using the Within Function
Here is my TERR script. The script performs three steps.
- Create an object called mytable that is equal to my input parameter.
- Create a new calculated column called BOE. Note, I lead with the table/object name and denote the column with “$”.
- Build a new object called mytable2. The within function adds the new column to mytable. Mytable2 is my output parameter.
Parameters
After writing the script, I setup my input and output parameters.
I only have one input parameter (Type = table).
I have one output parameter (Type = table) called mytable2.
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.
Pingback: Find Unique Values with TERR » The Analytics Corner
Pingback: Resolve Data Function Errors When Upgrading Spotfire » The Analytics Corner
Hi Julie, thanks for setting this up. I have two questions, any help is more than appreciated!
(1) When I follow these steps and click run, i’m lead to the edit parameters window where I’m asked to set up the “input handlers” and output handlers….what did you do for these steps?
(2) can you simply add the calculated column to the original data table rather than having to add to a second table?
First off, check out this post — https://datashoptalk.com/spotfire-data-functions-terr-basics/. I wrote this post so I didn’t have to re-write the same steps for every TERR post. I think this will help you understand the answer to question 1. Start reading where it says “Now that we understand what TERR is”.
To answer your questions.
1. Make sure that you setup input and output parameters in the Register Data Functions screen or else nothing else will make sense. In my post, they are called “input” and “mytable2”. But…
2. In order to add them to an existing table, you will need to change “mytable2” in the scrip to “mytable” and make the output parameter called “mytable”. This is basically overwriting the original mytable object (i.e. adding to an existing table.
3. When you get to the Edit Parameters screen, select Columns as the input handler and either choose specific columns or select Search expression and enter “*”. For Output, select overwrite the existing table. That will map the mytable object to an actual table in your project.
Julie – Thanks for the reply -> your suggestions worked great! Also I did just go through that additional post and it was extremely help, thank you!