Multiple if statements to satisfy the requirement

imaliuddin

New Member
Joined
Oct 26, 2019
Messages
2
Hello Experts,

I need your help to automate a long manual activity which takes allot of time. Every week I have received stock transfer requests of 500 line items from LHR and ISB to replenish the stock from KHI which is our central Warehouse to feed both locations. Please see below table with expected results which i want to be derived from formula. Purpose is to make inventory transfer of available quantity in KHI to LHR/ISB with equality keeping in view who has more deficit and who has more average monthly sales/consumption. Below are the conditions which I have made and if anyone of you feels that is not logical or need changes you can make changes in the attach excel file while replying to the solution.

[TABLE="width: 1349"]
<tbody>[TR]
[TD]Note:[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 17"]Stock can not be transfer in decimals and negative numbers it has to be a whole number so rounding would be required keeping in view the available stock in KHI up to the max of LHR and ISB average monthly sales.[/TD]
[/TR]
[TR]
[TD="colspan: 2"]Below are the logics[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 12"]1-Since KHI is our mother location so it has to be make sure KHI should not be < its monthly sales no matter LHR and ISB has zero stock[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 12"]2-If LHR or ISB has current stock = their monthly average sales then no transfer is required no matter quantities are available in KHI[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 10"]3-Transfer will only be executed if LHR / ISB has < its average monthly sales means if their current deficit < 100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 10"]4- if KHI has enough stock to fulfill both LHR/ISB requirement then relenish both upto their max deficit[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 10"]5- if KHI has only one extra qty and deficit of anyone location is >= 80% then proceed transfer to that location[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 13"]6- if KHI has only one extra qty and deficit of both location is >= 80% then check whose average sales is higher then otherone then proceed for that location[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 16"]7- if both locations deficit is equal and KHI available is not enough to satisfy both then the qty will be equally devided equally to both keeping in view of if quantity is ODD then it will be -1 then divided by 2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 16"]8- If one has defcit >= 80% and other has <=20% and available stock can completely fullfil the one has higher deficit then all feed to that one and if still have leftover stock in khi then send to other location[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 14"]9- If one has defcit >= 80% and other has <=20% and khi has not enough to fullfill the one has higher deficit completely then available stock will be splitted in 80-20% respectively[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 16"]10- If one has defcit >= 60% and other has <=35% and available stock can completely fullfil the one has higher deficit then all feed to that one and if still have leftover stock in khi then send to other location[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 14"]11- If one has defcit >= 60% and other has <=35% and khi has not enough to fullfill the one has higher deficit completely then available stock will be splitted in 60-35% respectively[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 14"]12- If one has defcit >= 45% and other has <=35% and khi has not enough to fullfill the one has higher deficit completely then available stock will be splitted in 45-35% respectively[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 16"]13- If one has defcit >= 45% and other has <=35% and available stock can completely fullfil the one has higher deficit then all feed to that one and if still have leftover stock in khi then send to other location[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 14"]14- If one has defcit >= 35% and other has <=20% then available stock will be splitted equally keeping in view if quantity is ODD then it will be -1 then divided by 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 13"]15- If one has defcit <= 35% and other has <=20% then available stock will be splitted equally keeping in view of ODD then it will be -1 then divided by 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 1086"]
<tbody>[TR]
[TD][/TD]
[TD="colspan: 3, align: center"]Average Monthly Sales[/TD]
[TD="colspan: 3, align: center"]Current Stock[/TD]
[TD="colspan: 4, align: center"]Current Deficit[/TD]
[TD="align: center"][/TD]
[TD="colspan: 2, align: center"]This is the expected outcome[/TD]
[/TR]
[TR]
[TD="align: center"]Items[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]LHR Qty[/TD]
[TD="align: center"]LHR%[/TD]
[TD="align: center"]ISB Qty[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]How much Extra in KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[/TR]
[TR]
[TD]Item-01[/TD]
[TD]81[/TD]
[TD]9[/TD]
[TD]21[/TD]
[TD]200[/TD]
[TD]20[/TD]
[TD]15[/TD]
[TD]11[/TD]
[TD]122%[/TD]
[TD]-6[/TD]
[TD]-29%[/TD]
[TD]119[/TD]
[TD]Enough Stock[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]Item-02[/TD]
[TD]67[/TD]
[TD]32[/TD]
[TD]28[/TD]
[TD]108[/TD]
[TD]25[/TD]
[TD]25[/TD]
[TD]-7[/TD]
[TD]-22%[/TD]
[TD]-3[/TD]
[TD]-11%[/TD]
[TD]41[/TD]
[TD]7[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Item-03[/TD]
[TD]57[/TD]
[TD]30[/TD]
[TD]11[/TD]
[TD]36[/TD]
[TD]33[/TD]
[TD]10[/TD]
[TD]3[/TD]
[TD]10%[/TD]
[TD]-1[/TD]
[TD]-9%[/TD]
[TD]-21[/TD]
[TD]KHI Low[/TD]
[TD]KHI Low[/TD]
[/TR]
[TR]
[TD]Item-04[/TD]
[TD]0[/TD]
[TD]26[/TD]
[TD]14[/TD]
[TD]36[/TD]
[TD]0[/TD]
[TD]7[/TD]
[TD]-26[/TD]
[TD]-100%[/TD]
[TD]-7[/TD]
[TD]-50%[/TD]
[TD]36[/TD]
[TD]26[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]Item-05[/TD]
[TD]66[/TD]
[TD]33[/TD]
[TD]17[/TD]
[TD]200[/TD]
[TD]10[/TD]
[TD]30[/TD]
[TD]-23[/TD]
[TD]-70%[/TD]
[TD]13[/TD]
[TD]76%[/TD]
[TD]134[/TD]
[TD]23[/TD]
[TD]Enough Stock[/TD]
[/TR]
[TR]
[TD]Item-06[/TD]
[TD]77[/TD]
[TD]26[/TD]
[TD]20[/TD]
[TD]118[/TD]
[TD]30[/TD]
[TD]36[/TD]
[TD]4[/TD]
[TD]15%[/TD]
[TD]16[/TD]
[TD]80%[/TD]
[TD]41[/TD]
[TD]Enough Stock[/TD]
[TD]Enough Stock[/TD]
[/TR]
[TR]
[TD]Item-07[/TD]
[TD]81[/TD]
[TD]15[/TD]
[TD]22[/TD]
[TD]90[/TD]
[TD]7[/TD]
[TD]15[/TD]
[TD]-8[/TD]
[TD]-53%[/TD]
[TD]-7[/TD]
[TD]-32%[/TD]
[TD]9[/TD]
[TD]5[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Item-08[/TD]
[TD]59[/TD]
[TD]10[/TD]
[TD]32[/TD]
[TD]67[/TD]
[TD]7[/TD]
[TD]18[/TD]
[TD]-3[/TD]
[TD]-30%[/TD]
[TD]-14[/TD]
[TD]-44%[/TD]
[TD]8[/TD]
[TD]1[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]Item-09[/TD]
[TD]42[/TD]
[TD]26[/TD]
[TD]27[/TD]
[TD]43[/TD]
[TD]17[/TD]
[TD]8[/TD]
[TD]-9[/TD]
[TD]-35%[/TD]
[TD]-19[/TD]
[TD]-70%[/TD]
[TD]1[/TD]
[TD]0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Item-10[/TD]
[TD]53[/TD]
[TD]40[/TD]
[TD]29[/TD]
[TD]66[/TD]
[TD]31[/TD]
[TD]22[/TD]
[TD]-9[/TD]
[TD]-23%[/TD]
[TD]-7[/TD]
[TD]-24%[/TD]
[TD]13[/TD]
[TD]7[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]

Thanks in advance
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Welcome to the MrExcel Board!

You have a LOT of rules, and I wonder how important each of them are. I don't know if you devised them, or if you're just the person designated to enforce them. I'm sure that it would be possible to come up with a set of formulas that encompass your rules exactly, but it would take a LOT of analysis, and would be quite cumbersome to maintain. I tried to come up with a method that maintains the general spirit of the rules, but is easier to incorporate. Consider:

Excel 2012
ABCDEFGHIJKLMN
Item-01Enough Stock
Item-02
Item-03Enough StockKHI Low
Item-04
Item-05Enough Stock
Item-06Enough StockEnough Stock
Item-07
Item-08
Item-09
Item-10

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: center"]Average Monthly Sales[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]Current Stock[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]Current Deficit[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]This is the expected outcome[/TD]
[TD="align: center"][/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]Items[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]LHR Qty[/TD]
[TD="align: center"]LHR%[/TD]
[TD="align: center"]ISB Qty[/TD]
[TD="align: center"]ISB%[/TD]
[TD="align: center"]How much Extra in KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]81[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]21[/TD]
[TD="align: right"]200[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]122%[/TD]
[TD="align: right"]-6[/TD]
[TD="align: right"]-29%[/TD]
[TD="align: right"]119[/TD]

[TD="align: right"]6[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]67[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]28[/TD]
[TD="align: right"]108[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-22%[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-11%[/TD]
[TD="align: right"]41[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]57[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]33[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]10%[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-9%[/TD]
[TD="align: right"]-21[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]0[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]-26[/TD]
[TD="align: right"]-100%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-50%[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]66[/TD]
[TD="align: right"]33[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]200[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]-23[/TD]
[TD="align: right"]-70%[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]76%[/TD]
[TD="align: right"]134[/TD]
[TD="align: right"]23[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]77[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]118[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]15%[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]80%[/TD]
[TD="align: right"]41[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]81[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]90[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]-8[/TD]
[TD="align: right"]-53%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-32%[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]4[/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]59[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]67[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-30%[/TD]
[TD="align: right"]-14[/TD]
[TD="align: right"]-44%[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]11[/TD]

[TD="align: right"]42[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]-9[/TD]
[TD="align: right"]-35%[/TD]
[TD="align: right"]-19[/TD]
[TD="align: right"]-70%[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]12[/TD]

[TD="align: right"]53[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]29[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]31[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]-9[/TD]
[TD="align: right"]-23%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-24%[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]6[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]H3[/TH]
[TD="align: left"]=F3-C3[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]I3[/TH]
[TD="align: left"]=H3/C3[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]J3[/TH]
[TD="align: left"]=G3-D3[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]K3[/TH]
[TD="align: left"]=J3/D3[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]L3[/TH]
[TD="align: left"]=E3-B3[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]M3[/TH]
[TD="align: left"]=IF(H3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-H3,ROUND(L3*-H3/(-H3+MAX(0,-J3)),0))))[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]N3[/TH]
[TD="align: left"]=IF(J3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-J3,ROUND(L3*-J3/(-J3+MAX(0,-H3)),0))))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



The formula first checks for whether LHR or ISB needs any stock, then checks if KHI has any available, and if so, assigns the available stock to LHR and ISB proportionately based on need. I was a bit surprised when it turned out that it matches your expected outcome exactly. I have little doubt that it will vary from your rules in some cases, but it should be pretty close. In fact I think an in-depth analysis of your rules and my formula (which I do not volunteer to do!) would show a lot more overlap than exceptions. Anyway, give it a try and see what you think.
 
Upvote 0
Dear Eric,

First of all thank you so much for replying me in such detail. I have tried your logics and results are preety much closer to what i am looking for. I have found some discrepancies as below if you can further eliminate those it would be of great help.

1. When both LHR(C) and ISB(D) has same avg monthly sales and same deficit as LHR(H) and ISB(J) and available quantity is only 1(L) then it returned LHR(M) 1 and ISB(N) 1 which is
practically not possible as KHI has only 1 extra to feed.

2. When both C and D has different avg sales and different deficit and available quantity is not enough to feed both but it feeds more then its available quantity to M and N

ABCDEFGHIJKLMN
How much Extra in KHI
KHILHRISBKHILHRISBLHR QtyLHR%ISB QtyISBLHRISB
Discrepancy-1812626821515-11-42%-11-42%1.0 (Only 1 available so can't feed to both)1.01.0
Discrepancy-2812625841514-11-42%-11-44%3 (Only 3 available so can't feed 2 to each)2.02.0


<tbody>
[TD="colspan: 3"]Average Monthly Sales[/TD]
[TD="colspan: 3"]Current Stock[/TD]
[TD="colspan: 4"]Current Deficit[/TD]

[TD="colspan: 2"]How much to transfer from KHI to..[/TD]

</tbody>

Thanks in advance.



Welcome to the MrExcel Board!

You have a LOT of rules, and I wonder how important each of them are. I don't know if you devised them, or if you're just the person designated to enforce them. I'm sure that it would be possible to come up with a set of formulas that encompass your rules exactly, but it would take a LOT of analysis, and would be quite cumbersome to maintain. I tried to come up with a method that maintains the general spirit of the rules, but is easier to incorporate. Consider:

Excel 2012
ABCDEFGHIJKLMN
Item-01Enough Stock
Item-02
Item-03Enough StockKHI Low
Item-04
Item-05Enough Stock
Item-06Enough StockEnough Stock
Item-07
Item-08
Item-09
Item-10

<tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: center"]Average Monthly Sales[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]Current Stock[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]Current Deficit[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]This is the expected outcome[/TD]
[TD="align: center"][/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]Items[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]
[TD="align: center"]LHR Qty[/TD]
[TD="align: center"]LHR%[/TD]
[TD="align: center"]ISB Qty[/TD]
[TD="align: center"]ISB%[/TD]
[TD="align: center"]How much Extra in KHI[/TD]
[TD="align: center"]LHR[/TD]
[TD="align: center"]ISB[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]81[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]21[/TD]
[TD="align: right"]200[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]122%[/TD]
[TD="align: right"]-6[/TD]
[TD="align: right"]-29%[/TD]
[TD="align: right"]119[/TD]

[TD="align: right"]6[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]67[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]28[/TD]
[TD="align: right"]108[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-22%[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-11%[/TD]
[TD="align: right"]41[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]57[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]33[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]10%[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-9%[/TD]
[TD="align: right"]-21[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]0[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]-26[/TD]
[TD="align: right"]-100%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-50%[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]66[/TD]
[TD="align: right"]33[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]200[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]-23[/TD]
[TD="align: right"]-70%[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]76%[/TD]
[TD="align: right"]134[/TD]
[TD="align: right"]23[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]77[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]118[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]36[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]15%[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]80%[/TD]
[TD="align: right"]41[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]81[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]90[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]-8[/TD]
[TD="align: right"]-53%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-32%[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]4[/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]59[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]67[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-30%[/TD]
[TD="align: right"]-14[/TD]
[TD="align: right"]-44%[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]11[/TD]

[TD="align: right"]42[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]-9[/TD]
[TD="align: right"]-35%[/TD]
[TD="align: right"]-19[/TD]
[TD="align: right"]-70%[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]12[/TD]

[TD="align: right"]53[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]29[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]31[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]-9[/TD]
[TD="align: right"]-23%[/TD]
[TD="align: right"]-7[/TD]
[TD="align: right"]-24%[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]6[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]H3[/TH]
[TD="align: left"]=F3-C3[/TD]
[/TR]
[TR]
[TH]I3[/TH]
[TD="align: left"]=H3/C3[/TD]
[/TR]
[TR]
[TH]J3[/TH]
[TD="align: left"]=G3-D3[/TD]
[/TR]
[TR]
[TH]K3[/TH]
[TD="align: left"]=J3/D3[/TD]
[/TR]
[TR]
[TH]L3[/TH]
[TD="align: left"]=E3-B3[/TD]
[/TR]
[TR]
[TH]M3[/TH]
[TD="align: left"]=IF(H3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-H3,ROUND(L3*-H3/(-H3+MAX(0,-J3)),0))))[/TD]
[/TR]
[TR]
[TH]N3[/TH]
[TD="align: left"]=IF(J3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-J3,ROUND(L3*-J3/(-J3+MAX(0,-H3)),0))))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



The formula first checks for whether LHR or ISB needs any stock, then checks if KHI has any available, and if so, assigns the available stock to LHR and ISB proportionately based on need. I was a bit surprised when it turned out that it matches your expected outcome exactly. I have little doubt that it will vary from your rules in some cases, but it should be pretty close. In fact I think an in-depth analysis of your rules and my formula (which I do not volunteer to do!) would show a lot more overlap than exceptions. Anyway, give it a try and see what you think.
 
Upvote 0
The issue is the ROUND part of the formula. If you have 2 values that are .5 and .5, then ROUND will round them both up to 1. There are a couple ways to get around this. First, you can change the N3 formula to:

=IF(J3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-J3,L3-N(M3),ROUND(L3*-J3/(-J3+MAX(0,-H3)),0))))

by adding the part in red, it makes sure that the sum of the LHR and ISB values does not exceed the L3 value. So essentially, if there is a ROUNDUP issue, the LHR formula will get the extra unit. If you want to give the extra unit to ISB, change the M3 formula instead.

The second option is to remove the ROUND from both formulas and use INT instead:

M3: =IF(H3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-H3,INT(L3*-H3/(-H3+MAX(0,-J3))))))
N3: =IF(J3>=0,"Enough Stock",IF(L3<=0,"KHI Low",MIN(-J3,INT(L3*-J3/(-J3+MAX(0,-H3))))))

This is roughly the equivalent of your requirement that if the number is odd, subtract 1 then divide by 2. Using INT essentially rounds down always. Try both versions and see which works best for you.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
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