sisense.com
✅ You are viewing documentation for the latest version of Compose SDK.
Version:

Function customFormula

customFormula( title, formula, context): Attribute

Creates a calculated attribute (a formula-based Attribute) from a valid custom formula.

This is the attribute counterpart of measureFactory.customFormula: the resulting element is consumed as a attribute (for example, in the category/breakBy of a chart's data options, or in dimensions of a query) and produces categorical/grouping values rather than an aggregated number.

Use square brackets ([]) within the formula to reference attributes. Each unique reference must be defined using a property:value pair in the context parameter. Supported functions include string functions (for example Concat, Left, Right) and conditional expressions (IF, CASE). See full list of supported dashboard functions for calculated attributes.

Only text data type is supported for calculated attributes.

Parameters

ParameterTypeDescription
titlestringTitle of the calculated attribute to be displayed
formulastringFormula used to compute the attribute's values
contextCustomFormulaContextFormula context as a map of names to attributes (and, in advanced cases, measures or filters)

Returns

Attribute

A calculated attribute instance

Example

Combine two attributes into a single text attribute.

const ageAndGender = attributeFactory.customFormula(
  'Age & Gender',
  'Concat([ageRange], " ", [gender])',
  {
    ageRange: DM.Commerce.AgeRange,
    gender: DM.Commerce.Gender,
  },
);

Bucket a numeric attribute into named groups with a CASE expression.

const ageGroup = attributeFactory.customFormula(
  'Age Group',
  "CASE WHEN [ageRange] = '0-18' THEN 'Minor' WHEN [ageRange] = '65+' THEN 'Senior' ELSE 'Adult' END",
  { ageRange: DM.Commerce.AgeRange },
);
Last Updated: