I want to determine a order quantity based on a required quantity and available price breaks, to minimise total costs.
I prepared a small section of the spreadsheet to clarify: orders.ods (15.2 KB).
In this spreadsheet, the price breaks are in cells F3:H4, the required quantity is in cell A4.
I found a way to determine the cost (formula in cell J4) which works excellent (experiment with the required quantity to see), no problems there.
What I really need is the quantity to order (cell I4), which could be calculated by using the OFFSET(), RANK() and IF() funcions; but the RANK() function only works on an array, not on a series of calculated values…
Is there a way (short of adding a bunch of cells to get the array needed for the RANK() function) to achieve this?
So far, I came up empty…
[additional info]
I came up with =IF(IF(D4>H3,D4*H4,H3*H4)=J4,MAX(D4,H3),"other") for the largest step, but aparently this trick is not nestable: when I substitute “other” with IF(D4>G3,D4*G4,G3*G4)=J4,MAX(D4,G3),D4 it produces a 504 error…