About Spectre Expressions
Spectre uses a simple expression language that is designed to be clean and consistent. Spectre expressions can be used in numerous contexts by changing the set of available functions and their behavior and can be parsed without regard for the context.
Spectre expressions are used in varying combinations for build, cplan, dive, measures, and qvset files. They are also available to ProDiver column calculations. A Spectre expression starts and ends with a backtick character (`).
The expression grammar supports the following data types, operators, and functions:
- Numbers, strings, and Booleans
- Nulls (no data) and unknowns (uncomputable values)
- Math and comparison operators
- Logical operators (and, or, not)
- Calculation functions
Each Spectre file type supports expressions for different sets of tags.
When using functions to create a new column of data, the type for the column is dictated by the type returned by the function. For example, to turn a string into a date, use the date function. For example:
- date("2016/04/27")
- date("2016-4-27", "YYYY-M-D")
- date("Apr 27, 2016", "MMM D, YYYY")
To turn a string into a period, use the period function. For example:
- period("standard", "year-month", "2017/04")
- period("gregorian month", "2016/04") (deprecated syntax)
- period("standard", "year-month", "2017-Apr", "YYYY-MMM")
- period("gregorian month", "2016-Apr", "YYYY-MMM") (deprecated syntax)
- period("iso 8601", "year-week", "2017-W17")
- period("iso8601 week", "2016-W17") (deprecated syntax)
- period("iso 8601", "year-week", "17/2017", "WW/YYYY")
- period("iso8601 week", "17/2016", "WW/YYYY") (deprecated syntax)
See Spectre Data Types and Operations.
Expressions can be constructed from a range of functions which can be categorized into the following sets:
You can use the Spectre functions in each file type, that is, build, cplan, and dive, with the following exception. You cannot use dimension functions, with the exception of dimcnt, or squash functions in Build scripts. Specifically, the following functions only work when there is a window of data, that is, in a cPlan or Dive, and only with column tags:
- dimaverage
- dimgeomean
- dimmax
- dimmedian
- dimmin
- dimpercentile
- dimstddev
- parent
- rank
- squash
- squash_right
See also: