Request assistance shortening formula with criteria and different tables

mrblister

Board Regular
Joined
Nov 20, 2016
Messages
191
Office Version
  1. 2019
Platform
  1. Windows
ABCDEFGH
1MATERIALS MADE BY EACH FACTORY
2Factory TypeOutput Type (used by FACTORY DETAILS table)Output amount (used by FACTORY DETAILS table)
3NutFactoryNut10
4FactoryThatMakesNutFactoryNutFactory3
5ScrewFactorySmallScrew6
6ScrewFactoryLargeScrew11
7
8
9FACTORY DETAILS
10FactoryNutFactoryFactoryThatMakesNutFactoryFactoryThatMakesNutFactoryScrewFactorySmallScrewFactoryLarge
11OutputTypeNutNutFactoryNutScrewScrew
12FactoryIDNutFactoryOutputNutFactoryThatMakesNutFactoryOutputNutFactoryFactoryThatMakesNutFactoryOutputNutScrewFactorySmallOutputScrewScrewFactoryLargeOutputScrew
13OvertimeActivationInHours113981
14RegularOutput2412113
15OvertimeOutput4131052
16
17
18MATERIALS OUTPUT
19Hours Worked (that day)NutScrewNutFactoryFactoryThatMakesNutFactoryScrewFactorySmallScrewFactoryLarge
20Day 00000111
21Day 110400210390111
22Day 25750515585111
23Day 32890637625111

<colgroup><col><col><col span="6"></colgroup><tbody>
</tbody>


OK, so I have 3 tables on 3 different sheets in a workbook. I've simplified the problem above. I need to shorten the formulas in C21:H23.
The formula is C21 is:
C20+(IFERROR(IF($B21 < (INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0))),INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)*LOOKUP(INDEX($A$3:$A$6,1),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 < (INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0))),INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)*LOOKUP(INDEX($A$3:$A$6,2),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 < (INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0))),INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)*LOOKUP(INDEX($A$3:$A$6,3),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 < (INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0))),INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)*LOOKUP(INDEX($A$3:$A$6,4),$E$19:$H$19,$E20:$H20),0))

There's a large repeating section (differences in bold), that I think can be replaced by something more space-efficient.

What the formula does:
  1. For every Factory Type, first check to see if Hours are high enough for Overtime Output.
  2. If yes, there's a specific overtime formula that needs to be run to calculate the Output for that Factory.
  3. If Hours are low enough (to not activate Overtime), then RegularOutput is used with a specific regular formula to calculate output.
  4. Then multiply that output by the number of that specific Factory.
  5. Finally, all the outputs from all Factories are summed together (and the amount from the previous day is added).

NOTES:
  • The tables I am using are far larger than these, which makes it necessary to shorten the formulas.
  • The formulas to calculate output depending if OvertimeActivationInHours is activated, are very different. I used simple placeholders above.
  • The formula is complicated by the fact that there are factories that make factories. So for the example of "FactoryThatMakesNutFactory" we need to take into account the Nut Factories it makes (FactoryThatMakesNutFactoryOutputNutFactory), PLUS the Nuts generated by those new Nut Factories (FactoryThatMakesNutFactoryOutputNut).
  • The values in "MATERIALS MADE BY EACH FACTORY" are used by "FACTORY DETAILS" table, which is why some of those values don't appear in the formula.

Any suggestions on how to condense this formula?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
OOPS, I just noticed that "MATERIALS MADE BY EACH FACTORY" table isn't relevant to the formula at all! I could just read in the factory names from the second table. I can't remove the first table now though, I'm unable to edit my original post to due the editing rules.
 
Last edited:
Upvote 0
That sure is a monster!!

In essence...
=(IFERROR(IF($B21 <
INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0)),
INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,
INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,1)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)
*LOOKUP(INDEX($A$3:$A$6,1),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 <
INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0)),
INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,
INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,2)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)
*LOOKUP(INDEX($A$3:$A$6,2),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 <
INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0)),
INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,
INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,3)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)
*LOOKUP(INDEX($A$3:$A$6,3),$E$19:$H$19,$E20:$H20),0))+
(IFERROR(IF($B21 <
INDEX($A$10:$F$15,MATCH("OvertimeActivationInHours",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0)),
INDEX($A$10:$F$15,MATCH("RegularOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0))*$B21*5,
INDEX($A$10:$F$15,MATCH("OvertimeOutput",$A$10:$A$15,0),MATCH(INDEX($A$3:$A$6,4)&"Output"&C$19,$A$12:$F$12,0))*$B21*3)
*LOOKUP(INDEX($A$3:$A$6,4),$E$19:$H$19,$E20:$H20),0))

hard to break it down, but I would be leaning towards breaking each part out into a helper column *(1 per part), then summing the helpers.
This has the advantage of making adjustments/trouble-shooting simpler, and you can see what each part is doing - which may make it easier to spot errors?
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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