Formula errors when nested into larger formula but not when calculated alone?

jhall_cb

New Member
Joined
Jul 14, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Please god someone give me some ideas because at the moment it looks like Excel is just screwing with me...

I haven't posted on this account before but no stranger to Excel, VBA or Formulas. Running Windows 10, Office 365. So, I have a biiig horrible formula with lots of things nested all over the place (See the horrendous code tag at the bottom of the post). Within said beast is the nested formula:
Excel Formula:
OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F20,,1)),4),"1","")&MATCH(OFFSET(F20,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F20,,-1))-1)=0
which produces a #VALUE error. Evaluating the first section produces a single cell offset range with a value of 0:
Excel Formula:
{0}=0
. Evaluating this returns TRUE, happy days. So why does the whole section error? I have tried checking data types, checking for text, wrapping both in a NUMBERVALUE function, all still error as a group but evaluate separately as expected.

To compound my confusion even further if I copy the above formula from its enormous nested parent and run in a separate cell it returns TRUE as it should in the cell value but returns a #VALUE error on the formula bar evaluation??

Goal is to return a Boolean TRUE/FALSE for a complex conditional formatting rule. Minisheet below of the data in question below, based on a PivotTable. Any ideas would be greatly appreciated.

Parent Formula:
Excel Formula:
=IF(AND(F3<>0,OFFSET(F3,-1,)<>F3),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=2,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2)),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=3,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),3)),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=4,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),3),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),4)),FALSE))),FALSE)

Minisheet:
OrgMapping Simulator 2.xlsm
EFGHIJK
1
2L4L5L6L7L8L9Sum of Headcount
30
40
50
60
70
82
90
100
110
12H&G UK - HR - Employee Development BL - 2270339170
13H&G UK - HR - Employee Development Team - 2270339150
14H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - CIS & EOS Development - 2270462800
15H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - Employee Development Compliance - 2280805400
16H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - Employee Development Trainers - 2280805380
175
180
19H&G UK - HR - Lynne Oates - 2280901430
20H&G UK - HR - Lynne Oates - 228090143LHR HR-BP - 2270339142
21H&G UK - HR - Roshnee Khandelwal - 2280901390
22H&G UK - HR - Roshnee Khandelwal - 228090139EMA HR Services - 2270339162
23H&G UK - HR - Roshnee Khandelwal - 228090139H&G UK - HR - EMA HR - 2280805464
24H&G UK - HR - Roshnee Khandelwal - 228090139HR Admin & Passes - 2280805475
25H&G UK - HR - Roshnee Khandelwal - 228090139HR Dept. Occ Health BL - 2270339100
26H&G UK - HR - Rowena Catling - 2280901420
27H&G UK - HR - Rowena Catling - 228090142HR Recruitment - 2280806604
280
Piviot
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:J502Expression=AND(MOD($A3+1,2)=0,B3=B2,ROW()<MATCH("Grand Total",$B:$B,0))textNO
B3:J502Expression=MOD($A3+1,2)=0textNO
K3:K373Expression=MOD($A3+1,2)=0textNO
B3:J502Expression=AND(MOD($A3,2)=0,B3=B2,ROW()<MATCH("Grand Total",$B:$B,0))textNO
B3:J502Expression=MOD($A3,2)=0textNO
K3:K373Expression=MOD($A3,2)=0textNO
 

Attachments

  • 1657824394245.png
    1657824394245.png
    202.4 KB · Views: 12

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Welcome to the Forum!

It looks like you're overcooking your formula. The bit you've posted:

=INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F20,,1)),4),"1","")&MATCH(OFFSET(F20,,-1),E$1:E$372,0))

can be written:

=INDEX(G:G,MATCH(E20,E$1:E$372,))

Can you describe what you're trying to do, and illustrate with a simple example? Almost certainly there will be a more succinct way to do this.

Also let us know whether the formula can use 365's functionality, or whether it needs to be compatible with older Excel versions?
 
Upvote 0
Hi Stephen, Thanks for the quick response.

Formula is slightly overcooked intentionally to be dynamic and save on editing across various ranges or rules but the issue I have in main is the odd behavior in the calculation being different when nested as I have never seen that. As you have mentioned, I'm sure there will be a more concise way to achieve what I need but I couldn't wrap my head around a vba loop to do it initially and somehow pieced the formula theory together as it will be for a conditional format anyway.

Ultimate goal is to simulate something called negative selection which we apply to survey reports. Reports are generated on a hierarchy basis and need a minimum of 7 responses to be generated. In addition to the rule of 7, negative selection will also remove the report with the second lowest value so that results on the level above are not transparent. Apologies as that is also not straight forward but demonstrated in the Minisheet below. Unfortunately I cannot restructure the data or visualize in a different way in the final solution, it has to be in this format and some kind of conditional format rule on the row. I've upgraded to 365 2 weeks ago so happy to use the features, something like LET may help but I haven't had a chance to play with new formulas yet.

The reason a standard index match would not work is that you are looking for the smallest value within each group of the hierarchy, not the whole range. Depending on how many reports are under 7 you may also need to look for the lowest 2/3/4 values. Also need to catch that parent nodes have child nodes in-between so the rule needs to skip.

Quick dirty example below - Team 3 & 5 have less than 7 responses so rule triggers. We also lose 2nd lowest value in the group so Team 2 triggers rule also. Moving to the next hierarchy level, the same applies, South Teams trigger the rule and we lose the 2nd lowest in the group which is 26 so West Teams need trigger also. The dataset I have contains 9 hierarchy levels (cols) total. Apologies for the essay - not simple to phrase without losing people.


OrgMapping Simulator 2.xlsm
ABACADAEAFAGAHAI
7Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
8Site AParent41
9Site AManagementParent41
10Site AManagementWest TeamsParent26
11Site AManagementWest TeamsTeam 1Child15
12Site AManagementWest TeamsTeam 2Child10Conditional Rule Level 4 = True
13Site AManagementWest TeamsTeam 3Child1Conditional Rule Level 3 = True
14Site AManagementNorth TeamsParent30
15Site AManagementNorth TeamsTeam 4Child30
16Site AManagementSouth TeamsParent5
17Site AManagementSouth TeamsTeam 5Child5
Piviot
Cell Formulas
RangeFormula
AB9,AB17:AD17,AB16:AC16,AB15:AD15,AB14:AC14,AB11:AD13,AB10:AC10AB9=AB8
 
Upvote 0
When you say: We also lose 2nd lowest value in the group, do you mean the first lowest value >=7?

If so, should you also lose Team 4 at Rule Level 4?
 
Upvote 0
No, group is offset -1 column OR first parent above - West Teams in this example.
Group values range AG10:AG13, however in this format AG10 is the parent and is essentially the subtotal so we drop down to AG11:AG13, array would be {15, 10, 1}..
 
Upvote 0
I'm not sure you've answered the question. I'm talking about North, not West, and trying to clarify what 2nd lowest means.

Suppose we have:

Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
Site AManagementNorth TeamsParent31
Site AManagementNorth TeamsTeam 4Child30
Site AManagementNorth TeamsTeam 5Child1

Is it correct that by your rules, we would
- Lose Team 5 (<7), and
- Lose Team 4 (2nd lowest)?

So if we have:

Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
Site AManagementNorth TeamsParent30
Site AManagementNorth TeamsTeam 4Child30

shouldn't we also lose Team 4?

And what about:

Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
Site AManagementNorth TeamsParent35
Site AManagementNorth TeamsTeam 4Child30
Site AManagementNorth TeamsTeam 5Child3
Site AManagementNorth TeamsTeam 6Child2

We lose Team 5 and Team 6 (both <7). Do we also lose Team 4 (lowest value>=7)?
 
Upvote 0
Please also let us know whether you have the BYROW function, i.e. can you replicate this?

ABCD
11236
245615
378924
Sheet1
Cell Formulas
RangeFormula
D1:D3D1=BYROW(A1:C3,LAMBDA(r,SUM(r)))
Dynamic array formulas.
 
Upvote 0
Haha this is the nightmare of this rule... In my example Team 4 will not trigger as it is >7 - No action taken.

As mentioned before, each row indicates a report to generate based on survey data. In your first example, due to Team 5 being <7 the rule triggers. Team 4 also triggers in this example because If you get results for the Team 4 and subtract from results for parent you can work out results so this silly rule says you lose both child nodes. The parent is fine as there is no transparency in the result sets.

Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
Site AManagementNorth TeamsParent31
Site AManagementNorth TeamsTeam 4Child30
Site AManagementNorth TeamsTeam 5Child1


In your other example, Team 5 & 6 are both <7 so they both trigger. No need for next lowest as there is no transparency when subtracting Team 4 results from the parent, it cannot narrow down to one team.

Node/Level 1Node/Level 2Node/Level 3Node/Level 4TypeResponses
Site AManagementNorth TeamsParent35
Site AManagementNorth TeamsTeam 4Child30
Site AManagementNorth TeamsTeam 5Child3
Site AManagementNorth TeamsTeam 6Child2



Confirm I can replicate
Excel Formula:
=BYROW(A1:C3,LAMBDA(r,SUM(r)))
at a quick look at the formula descriptions I think these are the kind of things that may make life a whole lot easier.
 
Upvote 0
Thanks, that's clearer. But just to be sure ...

If you have:
Team 1: 50
Team 2: 40
Team 3: 2

you can report only on Team 1, because if you reported on the Group (92), Team 1 (50) and Team 2 (40), you'd be able to deduce Team 3's results by subtraction. (And with a small Team <7 people it would too easy to guess individual results).

If you have
Team 1: 50
Team 2: 40
Team 3: 2
Team 4: 1
Team 5: 1

then presumably you still need to eliminate Team 2 (as well as Teams 3, 4 and 5), because otherwise you could still deduce results for 4 people, albeit in different teams, by subtraction?

If I'm correct, the rule could be phrased: If you have any group < 7 people, you must eliminate the smallest groups in order until you have eliminated at least 7 people. Is this correct?

EDIT:

Sorry, I just realised you answered this question in the previous post. You're saying that although in the my 2nd example, there are only 4 people, they are across more than one team, therefore no need to eliminate Team 2.

That makes the rule: If there is exactly one group < 7 people, you must eliminate that group and the next smallest group.
 
Last edited:
Upvote 0
Yesss, that's the logic. 1st Example is exactly right.

With the second, it would just be Teams 3-5 as each are <7 but the other two are okay... while you know only 4 people have responded you could not deduce which of the three teams their results related to. Or which of those three teams had 1 response or 2.

Also consider that this is essentially just the first tier, after this column it would nudge back and work a column at a time right to left. In a group with one child <7 under the parent you would lose both. I think phrased it would be something like.... for each group, if count(val<7)=1 then eliminate row plus 2nd smallest , if count(val<7)>=2 then matching rows only
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top