Using Global Variables inside Spotfire

Have you ever built an analysis file and either needed to enter the same values in many different plots or enter values that changed dynamically? If so, this tip is for you.

TIBCO Spotfire provides the ability to create properties on three components of an analysis file: the entire analysis document (called a Document property), a data table in the analysis (called a Data Table property), and a column in a data table (called a Column property). Future posts will discuss use cases for data table and column properties, but for today, we will focus on Document Properties.

They can be seen in the User Interface by going to Edit > Document Properties and then clicking on the Properties dialog. From here you can add properties, view existing properties, and edit or delete existing properties. 

Document Properties

Let�s assume you are creating an analysis file which includes currencies from different regions. Each region has its own currency, but you want to tally up the totals across all regions using US dollars. In order to do this, you need to use an exchange rate to convert the regional currency into US currencies. This can be done by creating a Calculated Column (http://stn.spotfire.com/stn/UserDoc.aspx?UserDoc=spotfire_client_help/ncfe/ncfe_what_is_a_calculated_column_.htm ) or a Custom Expression (http://stn.spotfire.com/stn/UserDoc.aspx?UserDoc=spotfire_client_help/ncfe/ncfe_custom_expressions_overview.htm ).

Document Property

So far so good. But now you want to use the exchange rate in another calculations or somewhere else in the analysis. You would need to hard code the exchange rates again into another calculation. This makes updating the exchange rates more complicated.

To make this easier and more efficient, you can utilize Document Properties, which act in this case as global variables. Create a new property for each region, by clicking on the �New� button in the Document Properties UI, and provide the name, data types, and value (in this case the exchange rate for the region).

 Document Properties

Continue to add new properties till you have one for each desired region.

 Document Properties

NOTE: These properties are stored within the analysis file so they are saved with the analysis and available when you open it back up.

You can now go back to your calculated column or custom expression and retrieve the value of the Document Property instead of the hard coded value.

Inside the dialog for both the Calculated Column and Custom expression dialog, you will find the DocumentProperty function, which can be used to retrieve the values from document properties.

 Document Properties

Update your expression so that DocumentProperty function is used to retrieve the value of each region, as shown below.

Document Properties

Presto, you have just created global variables that you can reuse across all your documents pages and visualizations. When you need to update the exchange rate, you can just go to the Document Properties dialog and edit the value.

Can we make it more efficient?

TIBCO Spotfire is not just a very robust visual analytic application, but it is also a robust and highly configurable and extensible platform. Using the Spotfire SDK, you can create a custom tool which shows up inside TIBCO Spotfire, which can retrieve the current exchange rates from another application, like the Currency Converter WebService from http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=10

The tool will retrieve the values for all rates stored as Document Properties and then update the document properties values. Now, when the business author wants to update the rates, he or she only needs to open the tool inside Spotfire to execute the update.

Can we make it even more efficient?

One of the TIBCO Spotfire SDK extension points allows you to create an event that is triggered when an analysis file opens. If you want the properties to be updated everytime you open the analysis file, you can build an extension that listens to this application event and then executes the call to the web service to update the properties. 

What is required?

To set the document properties and call them from within an expression, you need TIBCO Spotfire Professional 2.0 or later. To create the Tool or extension to call the web service, you either need a developer who is trained in TIBCO Spotfire SDKs or TIBCO Spotfire Professional Services. 


Want to learn more?

This topic and more is covered in the Using Parameters and Properties in your Analysis webinar which you can learn more about here.

Want more information on building analysis files? Take SP151 � TIBCO Spotfire Distributing Analytics either onsite, regionally, or using our blended training model.


Do you have any questions or comments on this? Please post them.