Forum Discussion

wallingfordce's avatar
wallingfordce
Data Pipeline
11-26-2025
Solved

Replacing values with text: Pivot 2 script

👋 Hello, I have clients doing this in Windows... Replace Values with Text - Pivot Table Widget | Sisense Align A Single Column In Pivot  They might end up with a script like this: wid...
  • AssafHanina's avatar
    11-30-2025

    hey wallingfordce​ ,

    Pivot table in Linux is using the Pivot 2.0 API .which has different syntax compare to the Windows Version. 
    The requirement is to transform Value into Text and apply Style for the target cell.

    Please find an example script which transform value into text and apply style. (Follow the documentation above for the Cell.Style properties)

    • Targets the Indicator value/measure column
    • Replaces numeric values with descriptive labels
    • Applies consistent styling to the modified cells (each value can have different style)
    // Specify the target value/measure column to modify
    const myTarget = {
     type: ['value'],
     values: [
      {
       title: 'Indicator' // Name of the column to apply the transformation to
      }
     ]
    };
    
    // Apply a transformation to each cell in the selected pivot column
    widget.transformPivot(myTarget, function(metadata, cell) {
        if (cell.value == 1) {
            cell.content = "First-Time Donor"; // Replace numeric value with descriptive label
            cell.style = {
                "text-align": "center",  // Center text horizontally
                "padding-left": "5px"   // Add spacing on the left side
            };
        } 
        else if (cell.value == 2) {
            cell.content = "Recurring Donor"; 
            cell.style = {
                "text-align": "center",  
                "padding-left": "5px"   
            };
        } 
        else {
            cell.content = "No Donor"; 
            cell.style = {
                "text-align": "center",  
                "padding-left": "5px"   
            };
        }
    });
    

    Example of the Indicator_value converted to Indicator text

    fyi DRay​ 

    best regards