Knowledge Base Article

Convert Negative Sign To Parentheses In Pivot

Introduction
By default SiSense formats negative numbers by using the minus sign, like -1500. Some people prefer to format negative numbers by using a parenthese, like (1500). This article shows how to edit a widget's script to format the numbers this way.
Implementation
The following screenshot shows how the widget was initially formatted.
There's one line that you may need to edit in order to get it to work in your environment.  The '2' in _.each($('td:nth-child(2) div' , e) refers to the column of the pivot chart that we are trying to format. Change this to the appropriate column number.
Here's a widget script:
widget.on('ready', function(se, ev){
 var e = element;
 var w = widget;
 var d = dashboard;
 
 var s='td:nth-child(X) div'
 
 for (i = 2; i < 15; i++) { 
   _.each($(s.replace("X",i.toString()) , e).not('.wrapper, .p-head-content'), function(cell){ 
   var num =  parseFloat($(cell).text()); 
   var negative = $(cell).text().replace("-","");
   if (num < 0) {
    $(cell).text('('+negative+')' );
   } 
  }) 
 }
})
After applying the changes to script, reload the widget, and you should be able to see the changes. Here's a screenshot of the results.
Updated 03-02-2023
No CommentsBe the first to comment