cancel
Showing results for 
Search instead for 
Did you mean: 

Pivot 2.0 - Replace the "-" Sign of a Negative Value by Parentheses

Ophir_Buchman
12 - Data Integration
12 - Data Integration

In Accounting, it is common to represent negative numbers with leading and trailing parentheses.
For example, negative two hundred is displayed as "(200)"

To change a negative number formatting in a pivot 2.0 chart - Add the following script to the pivot widget:

function getWidgetDocumentObject(widget) {
if (prism.activeWidget == null)
return document.querySelector('[widgetid="' + widget.oid + '"]').querySelector('pivot2');
else
return document.querySelector('pivot2');
}

widget.on('domready', function(widget) {
try {
console.log('DOM Ready script starting (wid=' + widget.oid + ')');
doc = getWidgetDocumentObject(widget);
cells = doc.querySelectorAll('.table-grid__cell');
negative_cells = Array.from(cells).filter(cell => !isNaN(parseInt(cell.innerText.replaceAll(',',''))) && parseInt(cell.innerText.replaceAll(',',''))<0)

negative_cells.forEach(function(element) {
element.lastChild.innerText = element.lastChild.innerText.replace('-','(') + ')';
});
}
catch (error) {
debugger;
console.error(error);
}
finally {
console.log('DOM Ready script complete (wid=' + widget.oid + ')');
}
});
Before After
Ophir_Buchman_1-1646680848427.png Ophir_Buchman_0-1646680774098.png
1 REPLY 1

magic_mic
7 - Data Storage
7 - Data Storage

I have used the script to replace "-" with () for negative values. But it causes the values in the pivot table not refreshing properly in my dashboard when I switched the filters from one to another in my dropdown option.