Sisense
Replacing Displayed Text Values in a Pivot Table Row
This guide explains a widget script that remaps raw text values (such as true/false) to friendlier display labels in a specific row level of a Pivot Table, without altering the underlying data.
Overview
Pivot Table data sometimes contains raw values, such as boolean strings ("true" / "false"), codes, or system-generated labels that are accurate but not user-friendly when displayed.
Rather than modifying the underlying data model or adding a calculated field, a widget script using the transformPivot API can remap how specific cell values are displayed, while leaving the source data untouched.
This article describes a script that replaces "true" and "false" text in a specific row level of a Pivot Table with "Yes" and "No".
Use Cases
Apply this script when:
- A Pivot Table row displays raw boolean strings (
true/false) and a more readable label is needed (Yes/No,Active/Inactive, etc.)
- A field contains coded or system values that should be displayed with friendlier labels, without creating a custom dimension or modifying the data source
- Display-only formatting is preferred over altering the ElastiCube or data model
Prerequisites
- Edit access to the widget script (Widget Options menu > Edit Script)
- A Pivot Table widget
- The row level (index) containing the values to be replaced, within the pivot's row hierarchy
Script
widget.transformPivot(
{
type: ['member'],
rows: [{ index: [1] }],
},
function (metadata, cell) {
// Skip the first row (rowIndex === 0)
if (metadata.rowIndex === 0) return;
const contentV = cell.content;
if (contentV === "true") {
cell.content = "Yes";
} else if (contentV === "false") {
cell.content = "No";
}
}
);How It Works
Step | Description |
Selector | widget.transformPivot takes a selector object identifying which cells to target. type: ['member'] limits the transformation to regular data cells (excluding headers, subtotals, and grand totals). rows: [{ index: [1] }] limits it further to the second row level (index 1, zero-based) in the pivot's row hierarchy. |
Callback | For each matching cell, the callback receives metadata (information about the cell's position) and cell (the cell object, including its rendered content). |
Optional row skip | if (metadata.rowIndex === 0) return; skips the first rendered row in this selection. Include this only if your layout requires it (for example, to leave a specific row unchanged); otherwise it can be removed. |
Value remapping | The cell's displayed text ( cell.content) is checked against the raw values "true" and "false" and replaced with "Yes" and "No" respectively. Cells with any other value are left unchanged. |
Customization
Property | Description |
rows: [{ index: [N] }] | Targets a specific row level in the pivot's row hierarchy. Use columns: [{ index: [N] }] instead to target a column level, or values: [{ index: [N] }] to target a specific measure column. |
type | Restricts which kind of cells are affected. ['member'] targets standard data cells. Other types (such as 'subtotal' or 'grandtotal') can be included if the same remapping should apply there. |
contentV === "true" / "false" | The raw values being matched. Update to match the actual values appearing in your data (for example, numeric codes, or other string values). |
cell.content = "Yes" / "No" | The display label shown in place of the matched value. Add additional else if branches to support more than two mapped values. |
metadata.rowIndex === 0 | The skip condition. Adjust or remove depending on whether a specific row position needs to be excluded from the transformation. |
Limitations and Considerations
- This script changes the displayed value only; exports, drill-throughs, and underlying calculations continue to use the original raw value.
- Matching is based on an exact string comparison (
cell.content === "true"). If the underlying value is a true boolean type rather than a string, or includes different casing or formatting, the condition will need to be adjusted accordingly.
- The row index targeted (
index: [1]) is specific to the pivot's row hierarchy as configured. If row levels are added, removed, or reordered, this index must be updated to continue targeting the correct level.
