I have this table:
measure Retrofit cost Savings PER MONTH
1 1000 400
2 1300 207
3 1500 232
4 1100 215
5 1000 241
6 1500 277
7 1000 354
8 900 364
9 1500 427
10 1000 440
11 1300 201
12 2000 460
13 1000 373
14 1300 272
15 1500 250
16 3000 314
17 1300 390
18 1000 490
how to sum "Retrofit Cost" values until reach a given value – let’s say 6000 – considering the highest "savings per month" values. So this would be:
measure 18+measure12+measure10+measure9=5500.
if we sum the next higher savings value would go over 6000.
>Solution :
=TAKE(SCAN(0,TAKE(SORT(B1:C18,2,-1),,1),LAMBDA(a,b,IF((a+b)<=6000,a+b,a))),-1,1)

