I have the following two formulas, which were expected to produce identical results. The one marked "Original" is verified to produce the expected results. It actually calls source data 4 different times, so I decided to consolidate the formula into the
one marked "New" to speed up the workbook. Unfortunately, it isn't doing what I thought it would.
The purpose of this formula is to scan a very large sheet of raw data, and sum monthly values for rows that meet specific criteria.
Original: just here for reference, I don't expect anyone to decipher it
{=(ROUND(SUM(IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,IF('FPA Warehouse'!$D$1:$D$5000="72_LABOR_TOT",IF(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D04",'FPA Warehouse'!$F$1:$Q$5000,0),0),0)),2)+ROUND(SUM(IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,IF('FPA
Warehouse'!$D$1:$D$5000="72_LABOR_TOT",IF(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D07",'FPA Warehouse'!$F$1:$Q$5000,0),0),0)),2))-(ROUND(SUM(IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,IF('FPA Warehouse'!$D$1:$D$5000="729545",IF(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D04",'FPA
Warehouse'!$F$1:$Q$5000,0),0),0)),2)+ROUND(SUM(IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,IF('FPA Warehouse'!$D$1:$D$5000="729545",IF(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D07",'FPA Warehouse'!$F$1:$Q$5000,0),0),0)),2))}
New:
{=(ROUND(SUM(IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,IF(OR(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D04",RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D07"),IF('FPA Warehouse'!$D$1:$D$5000="72_LABOR_TOT",'FPA Warehouse'!$F$1:$Q$5000,IF('FPA Warehouse'!$D$1:$D$5000="729545",-('FPA
Warehouse'!$F$1:$Q$5000),0)),0),0)),2))}
When I'm investigating non-working formulas, I often paste them into Word so I can reformat and indent, to more easily trace the logic (in this case, the pairing of the True and False parameters of each embedded IF statement. Vertically aligned rows are
the True/False statements for the IF above them.
(I removed the ROUND statement, since it wasn't relevant here). And yes, I am subtracting the values associated with 729545.
SUM(
IF('FPA Warehouse'!$A$1:$A$5000=AllLocData!I$3,
IF(OR(RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D04",RIGHT('FPA Warehouse'!$C$1:$C$5000,3)="D07"),
IF('FPA Warehouse'!$D$1:$D$5000="72_LABOR_TOT",
'FPA Warehouse'!$F$1:$Q$5000,
IF('FPA Warehouse'!$D$1:$D$5000="729545",
-('FPA Warehouse'!$F$1:$Q$5000)
,0))
,0)
,0)
)
So according to my thinking, all of the FALSE parameters are zero, and I should only get the matching rows/values. What is actually happening is that it is also pulling in the rows where either line 4 or 6 are true (="72_LABOR_TOT", and ="729545") where
row 3 is actually FALSE [e.g, RIGHT('FPA Warehouse'!$C$1:$C$5000,3) is not D04 or D07].
Here is some sample data; if you paste this into a blank sheet and name it "FPA Warehouse", then paste in the 'New' formula (Ctrl-Shft-Enter because it is an array formula) in a blank cell and change the "AllLocData!I$3" reference at the beginning of the
"new" formula to a cell you can put the number 555 in. I think that should replicate my situation. The original formula adds up the total for the lines that have BOLD in three columns. The new formula is including the lines with ITALICS in column D.
The expected result is 620,469. Any idea why I'm getting 639,390 (the inclusion of the two italics rows) instead?
Thank you!!
edit: apparently the table is wrapping within cells, the third column contains "LocName D04", and color was not maintained even though it was visible while I was creating the post :( so edited to be bold and italics instead
| 555 |
(blank) |
LocName D04 |
72_LABOR_TOT |
(blank) |
61,565 |
61,239 |
71,286 |
75,653 |
66,737 |
81,122 |
67,042 |
68,882 |
61,457 |
- |
- |
- |
| 555 |
(blank) |
LocName D04 |
723533 |
(blank) |
5,217 |
5,090 |
5,090 |
5,182 |
5,182 |
5,182 |
8,182 |
1,943 |
4,917 |
- |
- |
- |
| 555 |
(blank) |
LocName D04 |
729540 |
(blank) |
- |
- |
- |
(50) |
- |
- |
- |
- |
- |
- |
- |
- |
| 555 |
(blank) |
LocName D04 |
729545 |
(blank) |
(113) |
- |
- |
- |
- |
- |
(450) |
(4,923) |
- |
- |
- |
- |
| 555 |
(blank) |
LocName D04 |
72_OTH |
(blank) |
19,551 |
21,737 |
21,006 |
25,978 |
30,461 |
33,202 |
39,384 |
11,229 |
19,046 |
- |
- |
- |
| 555 |
(blank) |
LocName D04 |
72_W |
(blank) |
81,117 |
82,976 |
92,292 |
101,631 |
97,198 |
114,324 |
106,426 |
80,112 |
80,504 |
- |
- |
- |
| 555 |
(blank) |
LocName D06 |
72_OTH |
(blank) |
892 |
253 |
- |
9 |
298 |
783 |
641 |
660 |
799 |
- |
- |
- |
| 555 |
(blank) |
LocName D06 |
72_W |
(blank) |
892 |
253 |
- |
9 |
298 |
783 |
641 |
660 |
799 |
- |
- |
- |
| 555 |
(blank) |
ABC LocName |
72_LABOR_TOT |
(blank) |
1,891 |
1,854 |
2,250 |
2,102 |
2,294 |
2,112 |
2,119 |
2,153 |
2,148 |
- |
- |
- |
| 555 |
(blank) |
ABC LocName |
729545 |
(blank) |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
| 555 |
(blank) |
ABC LocName |
72_OTH |
(blank) |
- |
52 |
160 |
19 |
- |
- |
- |
17 |
- |
- |
- |
- |
| 555 |
(blank) |
ABC LocName |
72_W |
(blank) |
1,891 |
1,905 |
2,410 |
2,120 |
2,294 |
2,112 |
2,119 |
2,170 |
2,148 |
- |
- |
- |