Skip to content

KPI Method Overview

The addKpi method is mandatory for creating a new KPI, as it initializes the widget in the associated report.

Syntax:

$olap.addKpi(
"kpi_id",
"title_label",
"time_column",
"time_interval",
"target_value",
"real_value",
"yellow_budget_rate",
"green_budget_rate",
"trend_icon_mode",
"data_filter"
)

Example:

$olap.addKpi(
"OR_YTDM",
"Operating Revenue (Year-To-Day-Month)",
"[time_month_no]",
"YTDM",
"SUM(CASE WHEN [time_year] = ?period.getYear(-1) AND [dim_1] BETWEEN '3000' AND '3999' THEN [accounted_amount_dcur] * -1 ELSE 0 END) * (1 + 0.1)",
"SUM(CASE WHEN [time_year] = ?period.getYear() AND [dim_1] BETWEEN '3000' AND '3999' THEN [accounted_amount_dcur] * -1 ELSE 0 END",
"0.8",
"1.0",
"1",
"[dim_1_profit_or_loss_account] = 1"
)

Parameters:

ParameterRequiredDescription
kpi_idYesA user-defined unique identifier for this KPI. The kpi_id specified here must be passed as an argument to subsequent methods
title_labelYesThe text label displayed as the title of this KPI
time_columnConditionalSpecifies the column containing time-related data. Must match the period format specified in time_interval. Set to NULL if not required
time_intervalConditionalDelimits the time interval for the data used in the method. Valid arguments: YTD (default), NULL, TP, TPM, YTDM, 12M. Set to NULL if not required
target_valueYesDefines the target or benchmark for the KPI. Typically used for comparison with the actual value. Set to 0 if no target is required
real_valueYesDefines the actual (realized) value of the KPI to be compared against the target. Typically contains the expression for the current performance metric
yellow_budget_rateYesDefines the percentage of the budget at which the KPI color-status changes from red to yellow. Must be lower than green_budget_rate. Set to NULL if not required
green_budget_rateYesDefines the percentage of the budget at which the KPI color-status changes from yellow to green. Must be higher than yellow_budget_rate. Set to NULL if not required
trend_icon_modeYesControls how trend indicators and icons are displayed for the KPI. Set to NULL if not required. Valid arguments: 0 = Icon only, 1 = Icon and trend line, 2 = Trend line only, 3 = No icon or trend line
data_filterYesGeneral filter expression to limit which data is included for the KPI. Set to NULL if not required

Overrides the default data source for a KPI, allowing it to retrieve data from an alternative table or view. This is useful when KPI data is stored in a different dataset than the report’s main data source. Using filter and drill functionality works if the dimensions are equally named (same column names).

Syntax:

$olap.setKpiSource(
"kpi_id",
"alias_key",
"matrix_name"
)

Examples:

// Same database
$olap.setKpiSource(
"Operating Revenue (Year-To-Day-Month)",
"fact_general_ledger"
)
// External database
$olap.setKpiSource(
"Operating Revenue (Year-To-Day-Month)",
"mssql",
"fact_general_ledger"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
matrix_nameYesThe name of the alternative data source table or view
alias_keyNoThe connection key for an external database if the data source is in a different database

Defines the width of the KPI widget for different screen sizes, using Bootstrap grid classes. This enables responsive layouts so KPIs look good on mobile, tablet, and desktop devices.

Syntax:

$olap.setKpiSize(
"kpi_id",
"xs_size",
"sm_size",
"md_size",
"lg_size"
)

Example:

$olap.setKpiSize(
"Operating Revenue (Year-To-Day-Month)",
"XS12",
"SM3",
"MD3",
"LG3"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
xs_sizeYesWidth of the KPI on extra small screens (mobile). Valid arguments: XS1, XS2, …, XS12
sm_sizeYesWidth of the KPI on small screens (tablets). Valid arguments: SM1, SM2, …, SM12
md_sizeYesWidth of the KPI on medium screens (desktops). Valid arguments: MD1, MD2, …, MD12
lg_sizeYesWidth of the KPI on large screens (large desktops). Valid arguments: LG1, LG2, …, LG12

Defines the display format for a KPI value (e.g., number of decimals, thousand separators, percentage signs).

Syntax:

$olap.setKpiFormat(
'kpi_id',
'value_format'
)

Example:

$olap.setKpiFormat(
'Operating Revenue (Year-To-Day-Month)',
'###,##0.00'
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
value_formatYesThe display format for the column value, using standard formatting syntax (e.g., number of decimals, thousand separators, percentage signs)

Sets custom colors for a KPI based on its status thresholds (e.g., red = poor, green = good).

Syntax:

$olap.setKpiColors(
"kpi_id",
"blue_color",
"green_color",
"orange_color",
"red_color"
)

Example:

$olap.setKpiColors(
"Operating Revenue (Year-To-Day-Month)",
"blue",
"green",
"orange",
"red"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
green_colorYesThe color for KPI values above green_budget_rate (good performance)
yellow_colorYesThe color for KPI values between yellow_budget_rate and green_budget_rate (warning)
red_colorYesThe color for KPI values below yellow_budget_rate (poor performance)

Sets the image for a KPI widget, changing dynamically based on whether the KPI is in red, yellow, or green color-status. Available images: FontAwesome

Syntax:

$olap.setKpiIcons(
"kpi_id",
"red_image",
"yellow_image",
"green_image"
)

Example:

$olap.setKpiIcons(
"Operating Revenue (Year-To-Day-Month)",
"frown_o",
"meh_o",
"smile_o"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
red_imageYesImage to display when KPI value is below yellow_budget_rate
yellow_imageYesImage to display when KPI value is between yellow_budget_rate and green_budget_rate
green_imageYesImage to display when KPI value is above green_budget_rate

Changes the default display names for the target and actual (real) values in a KPI widget. Useful for giving the KPI more user-friendly labels.

Syntax:

$olap.setKpiTargetRealName(
"kpi_id",
"target_label",
"real_label"
)

Example:

$olap.setKpiTargetRealName(
"Operating Revenue (Year-To-Day-Month)",
"Budget",
"Actual"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
target_labelYesThe custom label to display for the target value
real_labelYesThe custom label to display for the actual value

Replaces the KPI’s numeric target and actual values with custom text labels. This is useful when the KPI should display a status message instead of numerical values.

Syntax:

$olap.setKpiTargetRealDisplayField(
"kpi_id",
"target_value",
"real_value"
)

Example:

$olap.setKpiTargetRealDisplayField(
"Operating Revenue (Year-To-Day-Month)",
"50 000 000",
"~ 43 000 000"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
target_valueYesText to show instead of the real target value
real_valueYesText to show instead of the real actual value

Sets the text style size for a KPI widget, adjusting how large the value appears.

Syntax:

$olap.setKpiStyleSize(
"kpi_id",
"style_size"
)

Example:

$olap.setKpiStyleSize(
"Operating Revenue (Year-To-Day-Month)",
"tiny"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
style_sizeYesDefines the text size. Valid arguments: huge (default), large, normal, small, tiny

Enables a trend line in the KPI widget that uses dynamic colors: red for negative values and green for positive values, regardless of KPI thresholds.

Syntax:

$olap.setKpiNegativePositiveLine(
"kpi_id"
)

Example:

$olap.setKpiNegativePositiveLine(
"Operating Revenue (Year-To-Day-Month)"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update

Adds a horizontal plot line at value = 0 in the KPI’s trend line chart to highlight the neutral threshold. This method depends on the trend-line being activated.

Syntax:

$olap.setKpiPlotLine(
"kpi_id"
)

Example:

$olap.setKpiPlotLine(
"Operating Revenue (Year-To-Day-Month)"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update

Hides the target value information from the KPI widget, showing only the actual (realized) value.

Syntax:

$olap.hideKpiTargetInfo(
"kpi_id"
)

Example:

$olap.hideKpiTargetInfo(
"Operating Revenue (Year-To-Day-Month)"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update

Adds a clickable link to the KPI widget that navigates to a report or another internal URL when the link is clicked.

Syntax:

$olap.setKpiUrlLink(
"kpi_id",
"internal_url"
)

Example:

$olap.setKpiUrlLink(
"Operating Revenue (Year-To-Day-Month)",
"x35_109"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
internal_urlYesThe clickable link. Part of or the full internal URL (e.g., report reference). The full internal URL in the example: http://localhost:18080/demo/ui#!x35_109

Adds a clickable external URL to a KPI widget. When the user clicks the link, they are redirected to the specified web address.

Syntax:

$olap.setKpiExternalUrlLink(
"kpi_id",
"external_url"
)

Example:

$olap.setKpiExternalUrlLink(
"Operating Revenue (Year-To-Day-Month)",
"https://www.deem.no/en/"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
external_urlYesThe clickable link. The full external URL

Controls how filters and OLAP-actions (slice, dice, drill and pivot) affect a KPI. You can choose whether the KPI responds to all filter scope, only header filters, or remains static.

Syntax:

$olap.setKpiFilterCollection(
"kpi_id",
"olap_scope"
)

Example:

$olap.setKpiFilterCollection(
"Operating Revenue (Year-To-Day-Month)",
"header"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update
olap_scopeYesDefines which OLAP-actions affect the KPI. Valid arguments: all = Respond to all actions, header = Respond only to header actions, report = Respond only to report-level actions

Hides the KPI widget from the dashboard if its value is NULL (empty or not calculated).

Syntax:

$olap.setKpiHideIfNull(
"kpi_id"
)

Example:

$olap.setKpiHideIfNull(
"Operating Revenue (Year-To-Day-Month)"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update

Hides the KPI widget from the dashboard if its calculated value is zero (0).

Syntax:

$olap.setKpiHideIfZero(
"kpi_id"
)

Example:

$olap.setKpiHideIfZero(
"Operating Revenue (Year-To-Day-Month)"
)

Parameters:

ParameterRequiredDescription
kpi_idYesThe unique identifier of the KPI to update