excel - Cumulative budget that skips entries that exceed budget - Stack Overflow

I have a column of item costs listed top-down in order of priority that I need to purchase with $100. I

I have a column of item costs listed top-down in order of priority that I need to purchase with $100. I would like to be able to maximize my $100 while maintaining my priority purchases as much as possible. I have created a cumulative cost column that states "over" whenever I am over the $100 budget, but I have later entries that still fit within that budget. How can I "skip" the over budget entries in my cumulative column?

Here is an example dataset:

Item Cost Cumulative Cost (Current Output) Desired Output
40 40 40
40 80 80
40 Over Over
20 Over 100
20 Over Over

I have a column of item costs listed top-down in order of priority that I need to purchase with $100. I would like to be able to maximize my $100 while maintaining my priority purchases as much as possible. I have created a cumulative cost column that states "over" whenever I am over the $100 budget, but I have later entries that still fit within that budget. How can I "skip" the over budget entries in my cumulative column?

Here is an example dataset:

Item Cost Cumulative Cost (Current Output) Desired Output
40 40 40
40 80 80
40 Over Over
20 Over 100
20 Over Over

And here is the formula I am using for the cumulative cost (current output): IF(SUM($A$1:A1) <= 100, SUM($A$1:A1), "Over")

Share Improve this question asked Mar 25 at 20:20 ElizaBeso000ElizaBeso000 1156 bronze badges 2
  • This is the knapsack problem. Formulas are probably not the right approach here. – BigBen Commented Mar 25 at 20:21
  • Do you have any suggestions for a different approach in excel? My dataset is small enough that I can do this manually but I'd like something I can automate for future datasets. – ElizaBeso000 Commented Mar 25 at 20:24
Add a comment  | 

2 Answers 2

Reset to default 2

=DROP(REDUCE(0,A1:A5,LAMBDA(a,b,LET(c,MAX(a)+b,VSTACK(a,IF(c<=100,c,"over"))))),1)

This takes the cumulative sum from too to bottom if each added value stays under the maximum.

So for the following data results in shown result, but will not look if the maximum can be met else way as pictured in the most right column:

Data formula result not formula result
50 50 50
30 80 skip
25 over 75
25 over 100
10 90 over
=IF(SUM($A$2:A2) <= 100, SUM($A$2:A2),
IF(LARGE(IF(ISNUMBER($D$1:D1),$D$1:D1),1)+A2<=100,
LARGE(IF(ISNUMBER($D$1:D1),$D$1:D1),1)+A2,"Over"))

With legacy Excel such as Excel 2013 you can apply this formula. The formula must be entered with ctrl+shift+enter as an arrayformula.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744170644a4561519.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信