Expression language details
If you learn how the expression language works, the creation of valid expressions will be easier. This topic attempts to explain some basic functionality of the language.
[
" and
"]
" characters (square brackets). The square brackets are also
required when the column name is the same as a function name, or when the
column name begins with a digit. For example:
[Column 1]
[Sum]
<>
around an expression, it is treated as
categorical. For example:
<[Category column 1]>
[Column1],[Column2]
AS
keyword to specify a new name for an expression, and
hide the underlying expression. For example:
[Column1]/([Column1]+[Column2])AS Quota
Note that when the axis expression contains commas, you cannot rename the entire axis, but you can define one name for each part of the expression:
[Column1] AS [My first column], [Column2] AS [My second column]
39+12*3
-(1-2)
See also Operators and Functions for complete descriptions of the available operators and functions.
Comments in expressions
If you create more complex expressions that need an explanation, it is possible to add comments to the expressions. Use '//' to specify that the text after the symbols is a comment.
For example:
Avg([Sales]) OVER Intersect([Cat], AllPrevious([Year]))
//Shows the average sales per category for all years, up until the current year.
[Sales]/1000 //The sales figure has been divided by a thousand to show values in kkr instead of SEK
Note that if you add comments to an expression on a visualization axis, it is expected that you continue using the custom expression dialog for all further editing. This is because the drag-and-drop operations affect and rearrange the expressions too much to be able to keep comments.
Escaping special characters
Because certain characters have a special meaning in the Spotfire expression language, you must perform some actions if you are going to use those characters for other purposes, such as including them in column names.
An escape character is a special character used to inform the expression language that the following character in a character sequence should be seen as a standard character rather than as an item performing its special purpose.
If a column name contains any square brackets then they must be
escaped. Escaping of brackets is performed by adding extra brackets before and
after the bracket: "[
" and "]]
". For example,
if the column name is
[Name]
, it would be written as
[[Name]]]
in an expression. When using the
Insert Column button in the Add calculated
column dialog (installed client only) to add columns, you will automatically
get the correct escaping of the column name.
Case sensitivity
- Variables, functions and
keywords are not case sensitive:
SUM(C1) = Sum(C1) = sum(C1)
- Column name references are case sensitive.
- Method call names are not case sensitive. All methods which are defined in the add-in framework can be used. See Operators and Functions for information about the different methods supported.
Expression results
An expression describes how a new column should be calculated. The
newly created column will have the same number of rows as all the other columns
in the data table. The default null handling behavior is that operations on
null return null. This means that if a new column is calculated as
[Column A]*2
and there are empty values on some rows
in Column A, then the new column will have empty values on those rows as well.
Categorical expressions, NEST and CROSS
<[Category column 1] nest [Category column 2]>
For example, if you have a data table containing some sales data for each month during two years, but the data for February is missing for 2020, the different options will give the following results:
Nest
<[Year] NEST [Month]>
Cross
<CROSS [Year] CROSS [Month]>
(The first CROSS is optional.)
Validation of values
Empty values are generated whenever a column value from the data table
is missing, when a calculation involves an invalid value, or by explicitly
writing
null
in the expression. Results that are
null
, are displayed as
(Empty)
or simply left blank. Null values can be
replaced using the
SN() function.
When aggregating within a column, the invalid value will be ignored, whereas row-wise calculations between columns will result in invalid values each time one of the involved columns contains an invalid value.
- Operators
A list of the operators you can use in custom or calculated expressions. - Functions
A number of different functions are available for use in expressions. - Data types
The list shows the available data types. - Properties in expressions
There are three types of properties available in TIBCO Spotfire that you can use in expressions and to control different settings: document properties, data table properties and column properties. The properties can be interpreted in two different ways, either as actual values or as text values that can be used instead of column names or measures.