0

I am trying add conditional formatting to the Rows section of a pivot table based on the results found in the values section of the pivot. I have already set the conditional formatting in the values section where if a field is blank, it gets highlighted yellow. My need is to be able to highlight the Employee name in yellow if the last Month showing on the pivot is blank ... which means the employee has been terminated. The attached picture is what the report would ideally look like when looking at results through April and through March. In both cases I highlighted the Employee names manually.

Data through April

[Data through April2

Sample data:

Employee,Title,Dept,Month,Value
Amy Johnson,Manager,Sales,January,1
Amy Johnson,Manager,Sales,February,1
Amy Johnson,Manager,Sales,March,1
Dane Jones,Director,Operations,March,1
Dane Jones,Director,Operations,April,1
Dennis Cage,Manager,Marketing,January,1
Dennis Cage,Manager,Marketing,February,1
Erick Smith,VP,Sales,January,1
Erick Smith,VP,Sales,February,1
Erick Smith,VP,Sales,March,1
Erick Smith,VP,Sales,April,1
3
  • What have you tried and what is the problem you encountered? Nov 23, 2021 at 22:19
  • While having January, February and March selected, I tried adding conditional formatting using this formula: =L8="" where L8 is the cell for Amy Johnson. That worked perfect, but the moment I selected just January or January and February, all the names got highlighted. Not sure how to add the pictures or file to the comment ... this is the first time I ask a question here.
    – JGO
    Nov 23, 2021 at 22:34
  • Better to edit your question instead of adding information in comments. You can link to images in your question like you did before, someone with enough reputation will likely embed them for you Nov 23, 2021 at 23:24

1 Answer 1

0

This should get you started in the right direction:

=OFFSET($H3,0,2+XLOOKUP(0,INT($K$2:$V$2<>""),SEQUENCE(1,12),"")-1)=""

enter image description here

enter image description here

INT($K$2:$V$2<>"") is returning a 12 column array of integers, containing either a 1 if row 2 has a value in that column (starting with K, which is where the first column header of my pivot table is), or zero, if it doesn't have a value in that column (i.e. it's gone past the last column header). This relies on you not having any other data or objects to the right of your pivot table such that there's enough space to display 12 months, which I assume you must need anyway otherwise you'll get an error message when you try to refresh the pivot table and there's no room for it to grow.

XLOOKUP is searching for the first '0' in the array returned by INT and returning the corresponding position as indicated by SEQUENCE(1,12), which is just a 12-column array of increasing integers. So, if the pivot table is display four months, then the XLOOKUP searches for zero, finds that the first zero is in the 5th position, and so returns 5 from the SEQUENCE. We are then subtracting 1 to get 4.

In addition to this, we know that there are two columns between the Employee name and the first Month column. So, OFFSET is just saying, "give me the value that is zero rows below this row and 2+4 columns to the right of this column". If the cell it finds is empty, then the rule formula returns TRUE and colors the name yellow.

You may need to further modify the formula to account for when the number of names in the pivot table drops below the number of rows specified in the AppliesTo range in order to avoid empty cells below the pivot table turning yellow.

1
  • 1
    I can't thank you enough for the help you provided. This worked perfect and nobody else I asked, was even close to helping like this, thank you so much. Indeed I added an ISBLANK condition to the formula to cover the scenarios at the bottom of the table to make sure they weren't highlighted. Thank you again!
    – JGO
    Dec 1, 2021 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .