configure_metrics
Configures the metrics to be calculated and displayed.
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
anddsAll
: Accessors to the dataset used as input.dsAll
refers to the entire dataset, whileds
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 theds
accessor. Note thatdsAll
remains unaffected. Multiplewhere
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 theMetrics
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.
Was this page helpful?