Formula Transform

The formula transform extends data objects with new values according to a calculation formula.

Transform Parameters

Property Type Description
expr Expr Required. The formula expression for calculating derived values.
as String Required. The output field at which to write the formula value.
initonly Boolean If true, the formula is evaluated only when a data object is first observed. The formula values will not automatically update if data objects are modified. The default is false.

Usage

{"type": "formula", "as": "logx", "expr": "log(datum.x) / LN10"}

This example computes the base-10 logarithm of x and stores the result as the logx field.

{"type": "formula", "as": "hr", "expr": "hours(datum.date)"}

This example extracts the hour of the date field, and stores the result as the hr field.