Knowledge Base Article

Change Grand Total Row To Display Difference In Pivot Widgets

In cases where we want to display the difference between two columns instead of using the default Grand Totals in Pivot widgets:
Include the following widget script:
function removeCommas(num){

numClean = num.replace(/,/g,"");

return numClean;

};

widget.on("domready", function(){

/* Set text to be shown grand total row*/
var diff = "Difference";

/* set variables and clean local for reading */
var num1 = removeCommas($("#prism-mainview > div > div.errvil-warpper > div > div > div > pivot > div > div.p-fixed-cols > div > table > tbody > tr:nth-child(1) > td.p-value.p-first-data-col > div").text());
var num2 = removeCommas($("#prism-mainview > div > div.errvil-warpper > div > div > div > pivot > div > div.p-fixed-cols > div > table > tbody > tr:nth-child(2) > td.p-value.p-first-data-col > div").text());

/* Change label text*/
$("#prism-mainview > div > div.errvil-warpper > div > div > div > pivot > div > div.p-fixed-cols > div > table > tbody > tr:nth-child(3) > td.p-grand-total-row-head.p-first-data-col > div > div > span").text(diff)


/* Change difference value and add locale format*/

$("#pivot_ > tbody > tr:nth-child(3) > td.p-value.p-first-data-col.p-total-row-val > div").text((num1 - num2).toLocaleString());

});


console.log("background script run");
Result:
Disclaimer:
* Tested on version 7.0
* Only works with 2 row Pivot widgets
Updated 03-02-2023

1 Comment

  • Does anyone in the Community have widget script to display Difference for Grand Column in pivot?  My table  will only have two columns (previous two months - not current month) - Thank you, Dennis