This step allows you to define custom metrics that can be calculated from the dataset.

Each metric is defined by a name, an optional description, and a script that calculates the metric. Optionally, you can set a hidden property to true to hide the metric from the UI.

Inside one metric, you can use another metric through the available object Metric like this: Metric["licenses_to_renew"].

The most important part of the metric definition is the Javascript code. This script can use ES2023 JS syntax and it must implement a function body that returns a number representing the computed metric value. Within a script, the following functions and objects are available:

  • ds and dsAll: Accessors to the dataset used as input. dsAll refers to the entire dataset, while ds is affected by the applied selection. If no selection is made, both accessors refer to the same dataset.
  • count(ds): A function that returns the number of rows in the dataset.
  • where("queryString", () => { /* 'ds' accessor is a subset filtered by the query and the global selection */ }): A function that applies a filter to the ds accessor. Note that dsAll remains unaffected. Multiple where calls can be nested. See Advanced query filters for more information on query strings.
  • Metrics: You can reference another metrics within a metrics script using the Metrics object, e.g., Metrics["licenses_to_renew"].

Each column in the dataset has several aggregation operations available, depending on its data type. These operations can be accessed as if they were fields of the column, using dot notation. For example:

  • For a numerical column ‘sales’: ds.sales.sum or ds.sales.mean
  • For a categorical column ‘department’: ds.department.uniqueValues
  • For a text column ‘description’: ds.description.wordCount
  • For a date column ‘order_date’: ds.order_date.min or ds.order_date.max

You can use the following operations directly in your metric script to perform calculations on the dataset columns:

ALL ColumnTypes:

  • .nullRows: Returns the number of null rows in the column.
  • .validRows: Returns the number of non-null rows in the column.

NUMERICAL and DATE:

  • .count: Returns the number of non-null values in the column. If the column is a List this will count each element.
  • .sum: Calculates the sum of all values in the column.
  • .stddev: Calculates the standard deviation of the values in the column.
  • .variance: Calculates the variance of the values in the column.
  • .mean: Calculates the average of all values in the column.
  • .min: Returns the minimum value in the column.
  • .p25: Calculates the 25th percentile of the values in the column.
  • .p50: Calculates the 50th percentile (median) of the values in the column.
  • .median: An alias for .p50, calculates the median of the values in the column.
  • .p75: Calculates the 75th percentile of the values in the column.
  • .max: Returns the maximum value in the column.

CATEGORICAL:

  • .count: Returns the number of non-null values in the column. If the column is a List this will count each element.
  • .uniqueValues: Returns the number of unique values in the column.

TEXT:

  • .wordCount: Calculates the total number of words across all non-null rows in the column.
metrics
array[object]
required

Metrics list. The list of metrics to be calculated and displayed has the following properties:

  • name: The ID for the metric. No duplicated names are allowed.
  • description: An optional description of the metric.
  • script: The javascript code that calculates the metric. The metric should return a number.
  • hidden: A boolean that indicates whether the metric should be hidden. Useful for auxiliary metrics.
difference
string

Show difference. Whether to show the difference between the metric of the selection and the metric of the total population.

Values must be one of the following:

  • ABSOLUTE
  • RELATIVE