Filter a Filtered array based on a range for summing values

Kotta

New Member
Joined
Jul 15, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have a list of tickers and associated values that's an array resulting from sorting another column using the sort formula. I want to see if I can use a formula in excel to filter that array (C4 through D14) to show me the combination of tickers whose values sum up between 500M and 510M. Any ideas?
1720838740919.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Here is an attempt although I am not sure if it is the desired output:

Excel Formula:
=LET(
tags,C4:C14,
amounts,D4:D14,
min,D1,
max,E1,
combinations,TEXTAFTER(DROP(REDUCE("",TOCOL(amounts),LAMBDA(a,b,VSTACK(a,a&" | "&b))),1)," | ",1),
sum,DROP(REDUCE(0,TOCOL(amounts),LAMBDA(a,b,VSTACK(a,a+b))),1),
filter,FILTER(combinations,(sum>=min)*(sum<=max)),
array,--(IFERROR(DROP(REDUCE("",filter,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b," | ")))),1),0)),
total,BYROW(array,LAMBDA(a,SUM(a))),
column,TOCOL(HSTACK(array,total)),
tables,FILTER(column,column<>0),
tag,XLOOKUP(tables,amounts,tags,"Sum:"),
HSTACK(tag,tables))
 
Upvote 0
Here is an attempt although I am not sure if it is the desired output:

Excel Formula:
=LET(
tags,C4:C14,
amounts,D4:D14,
min,D1,
max,E1,
combinations,TEXTAFTER(DROP(REDUCE("",TOCOL(amounts),LAMBDA(a,b,VSTACK(a,a&" | "&b))),1)," | ",1),
sum,DROP(REDUCE(0,TOCOL(amounts),LAMBDA(a,b,VSTACK(a,a+b))),1),
filter,FILTER(combinations,(sum>=min)*(sum<=max)),
array,--(IFERROR(DROP(REDUCE("",filter,LAMBDA(a,b,VSTACK(a,TEXTSPLIT(b," | ")))),1),0)),
total,BYROW(array,LAMBDA(a,SUM(a))),
column,TOCOL(HSTACK(array,total)),
tables,FILTER(column,column<>0),
tag,XLOOKUP(tables,amounts,tags,"Sum:"),
HSTACK(tag,tables))
I see what you are doing. Very interesting approach but not quite what I am looking for. I appreciate it though!!
 
Upvote 0
Here's one way to do it but limited to 20 items since the row limit of Excel is 2^20.
Book1
CDEFG
1Range500,000,000.00510,000,000.00
2
3
4CombinationsSum
5A235,124,356A, C, D, E, F, H, I, J, K500,750,160.00
6B111,046,425A, B, D, E, F, J501,483,426.00
7C90,518,145A, B, C, E, I, J501,483,426.00
8D69,989,865A, C, D, E, F, G, I, J501,817,007.00
9E49,461,586A, B, D, E, F, J, K502,483,426.00
10F28,933,306A, B, C, E, I, J, K502,483,426.00
11G12,456,835A, C, D, E, F, G, I, J, K502,817,007.00
12H10,389,988A, B, D, E, F, I502,960,564.00
13I8,405,026A, B, C, E, H, J503,468,388.00
14J6,927,888A, C, D, E, F, G, H, J503,801,969.00
15K1,000,000A, B, D, E, G, H, I, J503,801,969.00
16A, B, C, F, G, H, I, J503,801,969.00
17A, B, D, E, F, I, K503,960,564.00
18A, B, C, E, H, J, K504,468,388.00
19A, C, D, E, F, G, H, J, K504,801,969.00
20A, B, D, E, G, H, I, J, K504,801,969.00
21A, B, C, F, G, H, I, J, K504,801,969.00
22A, B, D, E, F, H504,945,526.00
23A, B, C, E, H, I504,945,526.00
24A, C, D, E, F, G, H, I505,279,107.00
25A, B, C, E, G, J505,535,235.00
26A, B, D, E, F, H, K505,945,526.00
27A, B, C, E, H, I, K505,945,526.00
28A, C, D, E, F, G, H, I, K506,279,107.00
29A, B, C, E, G, J, K506,535,235.00
30A, B, C, D506,678,791.00
31A, B, D, E, F, G507,012,373.00
32A, B, C, E, G, I507,012,373.00
33A, B, C, D, K507,678,791.00
34A, B, D, E, F, G, K508,012,373.00
35A, B, C, E, G, I, K508,012,373.00
36A, B, C, E, G, H508,997,335.00
37A, B, D, E, F, I, J509,888,452.00
38A, B, C, E, G, H, K509,997,335.00
Sheet4
Cell Formulas
RangeFormula
F5:G38F5=LET(c,DROP(MID(REDUCE(0,C5:C15,LAMBDA(a,c,VSTACK(a,a&", "&c))),4,9^9),1), s,DROP(REDUCE(0,D5:D15,LAMBDA(a,c,VSTACK(a,a+c))),1), SORT(FILTER(HSTACK(c,s),(s>=F1)*(s<=G1)),2))
Dynamic array formulas.
 
Upvote 0
I see what you are doing. Very interesting approach but not quite what I am looking for. I appreciate it though!!

Thanks for the feedback. Could you please specify what is the desired output?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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