Hello Community,
Recently I had the thought of combining a value with an arrow (or anything else I suppose!) within a pivot table.
After getting inspiration from some links to the community
I mixed them up with some additional help and I ended up with a template script that:
Based on the pre-defined targetColumns on a pivot table returns both the value & the arrow (example below)
The script is:
widget.on('initialized', function (ev, se) {
// List of target columns by title
var targetColumns = ['']; // add your column names here
var colorGreen = 'green';
var colorRed = 'red';
var colorOrange = 'orange';
widget.transformPivot({
type: ['value', 'member'] },
function (metadata, cell) {
if (metadata.measure && targetColumns.includes(metadata.measure.title) && metadata.rowIndex !== 0){
var originalValue = cell.value;
var numericValue = (originalValue === null || originalValue === '') ? NaN : Number(originalValue);
var arrowChar = '━'; // Default arrow
var arrowColor = colorOrange; // Default color
if (!isNaN(numericValue)) {
if (numericValue > 0) {
arrowChar = '▲';
arrowColor = colorGreen;
} else if (numericValue < 0) {
arrowChar = '▼';
arrowColor = colorRed;
} else {
arrowChar = '━';
arrowColor = colorOrange;
}
var percentage = (numericValue * 100).toFixed(1) + '%';
cell.content = percentage + ' ' + arrowChar;
} else {
cell.content = arrowChar;
}
cell.style.color = arrowColor;
}
}
);
});
Notes:
- The arrows are included when exporting in PDF
Hope you will find this helpful!!
Updated 06-09-2025
Version 6.0MikeGre
ETL
Joined December 03, 2021
Use Case Gallery
Find inspiration for your visualizations, or show off your best work and tell us how you did it!