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

Function customFormula

customFormula( title, formula, context?, format?, description?): CalculatedMeasure

Creates a calculated measure for a valid custom formula built from base functions.

Use square brackets ([]) within the formula property to include dimensions, measures, or filters. Each unique dimension, measure, or filter included in the formula must be defined using a property:value pair in the context parameter.

You can nest custom formulas by placing one inside the formula parameter of another.

Note: To use shared formulas from a Fusion instance, you must fetch them first using useGetSharedFormula.

Note: Date measures, such as MAX([date]), cannot be combined with numeric values.

Parameters

ParameterTypeDescription
titlestringTitle of the measure to be displayed in legend
formulastringFormula to be used for the measure
context?CustomFormulaContextOptional formula context as a map of strings to attributes, measures, or filters
format?stringOptional format string for the measure
description?stringOptional description of the measure

Returns

CalculatedMeasure

A calculated measure instance

Example

An example of constructing a custom formulas using dimensions, measures, and nested custom formulas from the Sample Ecommerce data model.

// Custom formula
const profitabilityRatio = measureFactory.customFormula(
  'Profitability Ratio',
  '([totalRevenue] - SUM([cost])) / [totalRevenue]',
  {
    totalRevenue: measureFactory.sum(DM.Commerce.Revenue),
    cost: DM.Commerce.Cost,
  },
);

// Nested custom formula
const profitabilityRatioRank = measureFactory.customFormula(
  'Profitability Ratio Rank',
  'RANK([profRatio], "ASC", "1224")',
  {
    profRatio: profitabilityRatio,
  },
);

Another example of constructing a custom formula using measures and filters

const totalCostWithFilter = measureFactory.customFormula(
  'Total Cost with Filter',
  '(SUM([cost]), [categoryFilter])',
  {
    cost: DM.Commerce.Cost,
    categoryFilter: filterFactory.members(DM.Category.Category, ['Apple Mac Desktops']),
  },
);
Last Updated: