Caron Posted June 13, 2023 Report Share Posted June 13, 2023 Hi There I am trying to colour the rows in a Pivot Table - Currently looks as follows: Want to look something like this - highlight the phase and any amount within that phase. Any help would be appreciated. Many thanks.....Caron Quote Link to comment Share on other sites More sharing options...
0 Tubby Posted June 13, 2023 Report Share Posted June 13, 2023 Hey, maybe this helps. You just need to change the conditions and values used Quote Link to comment Share on other sites More sharing options...
0 CoopperBackpack Posted June 15, 2023 Report Share Posted June 15, 2023 Hi @Caron, I created a test Pivot table in my account that has the same layout as on your screenshot. This is the output: I used this code in the Footer section of the 'Configure Pivot Table Fields' page: <script> document.addEventListener('DataPageReady', colorCellsHandler); function colorCellsHandler() { //phases field (field used for a condition to color cells) const phases = document.querySelectorAll('td:nth-child(2)'); //cells with phases; add more variables if there are more phases let concept = []; let schematic = []; let development = []; let construction = []; let services = []; //looping through the phases field to populate the array with elements phases.forEach(phase => { const selectCells = (array) => { //exclude Grand Total field by filtering the elements let siblings = Array.from(phase.parentNode.children).filter(child => child !== phase.parentNode.lastChild); array.push(siblings); } if(phase.innerText == '02_Concept'){ selectCells(concept); } else if(phase.innerText == '03_Schematic Design'){ selectCells(schematic); } else if(phase.innerText == '04_Design Development'){ selectCells(development); } else if(phase.innerText == '05_Construction Documentation'){ selectCells(construction); } else if(phase.innerText == '06_Site Services'){ selectCells(services) } }) //appling color for cells with each phase, empty cells are excluded const colorCells = (cells, color) => { cells.forEach(cell => { cell.forEach(el => { if(el.innerText !== "") { el.style.backgroundColor = color; } }) }) } //replace color codes for each phase colorCells(concept, '#e8aab5'); colorCells(schematic, '#d5aae8'); colorCells(development, '#a0aef1'); colorCells(construction, '#e8ca7d'); colorCells(services, '#e87d95'); document.removeEventListener('DataPageReady', colorCellsHandler); } </script> You may provide all possible phases and colors you want to apply, so I can modify the code. Is it the result you wanted to achieve? It is possible to modify the code above and to style the Pivot table like this. But the code for this layout is less productive from the performance point of view. Feel free to update this thread in case you have any questions. Tubby 1 Quote Link to comment Share on other sites More sharing options...
Question
Caron
Hi There
I am trying to colour the rows in a Pivot Table - Currently looks as follows:
Want to look something like this - highlight the phase and any amount within that phase.
Any help would be appreciated. Many thanks.....Caron
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.