FILTERing an array using an array

narnian_uk

New Member
Joined
Jul 28, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello - I'd be very grateful for any thoughts you might have re the following:

I have a range of data, D1:Q21. Column D contains IDs; the remaining columns contain 0s or 1s or blanks associated with those IDs. Duplicate IDs will occur (as in rows 3 and 12 below). I am trying to write a formula which will sum each column for each ID - so if, as in this example, ID "ghi" has one set of entries on row 3 which read 0, 0, 0, 0, 1, 0... and another set of entries on row 12 which read 1, 1, 1, 1, 1,..., the formula will produce 1, 1, 1, 2, 1... by adding the two rows together.

At the moment, I have a column S which uses the UNIQUE function to get a list of all IDs, and then individual formulae next to each ID in column T to produce the column sums for that ID:

Excel Formula:
=LET(b,FILTER($F:$P,$D:$D=$S1,0),c, IF(ISNUMBER(b)=FALSE,0,b), MMULT(SEQUENCE(1,ROWS(c),1,0),--c))

(where $S1 becomes $S2 for the second ID, and so on). That works, but I'd rather have one cell containing a formula which produces the entire list of IDs and the sums for each ID because I never know how many IDs there will be in the original data. I tried this:

Excel Formula:
=LET(a, UNIQUE(FILTER(D:D, D:D<>"")), b,FILTER($F:$P,$D:$D=a,0),c, IF(ISNUMBER(b)=FALSE,0,b), MMULT(SEQUENCE(1,ROWS(c),1,0),--c))

but it doesn't work, presumably because the condition in the FILTER function can't compare a column with an array.

Any thoughts?

Sample.xlsx
DEFGHIJKLMNOPQRSTUVWXYZAAABACAD
1abc0000000010abc00000000010
2def0000111111def00001011111
3ghi0001011111ghi11121022212
4jklm1000110011jklm10001010011
5nop1001111110nop10011011110
6qrs1000011011qrs10000011011
7tuv0000000111tuv00000000111
8wxy0001010111wxy00010010111
9z121011111111z1210111011111
10345111111111134511111011111
11678100111011167810011010111
12ghi1111111101a1b10111011011
13a1b1011111011c2d00010011010
14c2d0001011010e3f11111011111
15e3f1111111111g4h11111011111
16g4h1111111111i5j11111010010
17i5j1111110010k6l00000011111
18k6l0000011111m7n00110010011
19m7n0011010011o8p00000010010
20o8p0000010010q9r00000010010
21q9r0000010010
Sheet1
Cell Formulas
RangeFormula
S1:S20S1=UNIQUE(FILTER(D:D, D:D<>""))
T1:AD20T1=LET(b,FILTER($F:$P,$D:$D=$S1,0),c, IF(ISNUMBER(b)=FALSE,0,b), MMULT(SEQUENCE(1,ROWS(c),1,0),--c))
Dynamic array formulas.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
How about
Excel Formula:
=LET(u,UNIQUE(FILTER(D1:D10000,D1:D10000<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,BYCOL(FILTER(F1:P10000,D1:D10000=y),LAMBDA(bc,SUM(bc))))))),1))
 
Upvote 0
How about
Excel Formula:
=LET(u,UNIQUE(FILTER(D1:D10000,D1:D10000<>"")),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,BYCOL(FILTER(F1:P10000,D1:D10000=y),LAMBDA(bc,SUM(bc))))))),1))
Well, this looks like some kind of wizardry, but it works. Thank you so much. I don't suppose you have a moment to explain the basic logic, do you...?
 
Upvote 0
The bycol filters the data based on the distinct values in col D & adds up each col & the reduce/vstack stacks them on top of each other.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
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