Knowledge Base Article

Financial Formatting for Pivot Tables on Linux

Question

How to apply Financial Formatting to Pivot Tables?

Answer

Financial reports usually have specific styling requirements where negative numbers are shown in parentheses as opposed to having a leading minus sign. They are also usually written in red.  

The script below formats all the negative numbers in pivot tables exactly as the requirements above. Feel free to modify it if you have different formatting requirements.

// Format negative numbers
widget.transformPivot({ type: ['value'] }, function(metadata, cell) {
	
    if(cell.value >= 0 || !cell.value) {
        cell.content = cell.value;
		cell.contentType = 'html';

    } else
	{
	  	cell.content ='(' + (-1*cell.value).toString() + ')';
  		cell.style.color = 'red';
        cell.contentType = 'html'; 
    }
});
Published 07-17-2024
No CommentsBe the first to comment