Filtered 2D array

vampsthevampyre

New Member
Joined
Apr 29, 2016
Messages
32
Office Version
  1. 365
Platform
  1. Windows
After yesterdays success of running totals in 2D arrays (Thanks Fluff), I have now hit another problem filtering the results.

I have generated a 2D array similar to the one shown below (this is a cut down version) cells O5-X14 and I'm trying to generate the two outputs AA5-AA14 and AC5-AE14. I wish to be able to use the number of filtered numbers in following equations i.e for results AC9,AD9 and AE9 there would be three different follow up equations up to a possible 10 in this example (max number of columns) so any solutions on how to also reference the filtered results would also be appreciated.

Regards

Ian

Book1
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
2
3OutputFiltered
4Column1Col1Col2Col3Col4Col5Col6Col7Col8Col9Col10Dynamic ArrayNo.s12345678910
5Row11000001000011
6Row22002000000012
7Row3690000609000269
8Row41200120000000112
9Row513413040000003134
10Row67000007000017
11Row7230002000300223
12Row800000000000
13Row915701005007003157
14Row10890008009000289
15
Sheet6
Cell Formulas
RangeFormula
O5:X14O5=Table13[[Col1]:[Col10]]
Dynamic array formulas.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hello,

In AA4 (count of outputs>0) you can enter :

Excel Formula:
=BYROW(O4#,LAMBDA(r,SUMPRODUCT(--(r>0))))

And in AC4 :

Excel Formula:
=LET(
matIni;O4#;
matRes,DROP(REDUCE(0,SEQUENCE(ROWS(matIni)),LAMBDA(acc,i,VSTACK(acc,
TOROW(FILTER(CHOOSEROWS(matIni,i),CHOOSEROWS(matIni,i)>0,""))))),1),
IFERROR(matRes,""))

However, in the "filtered results", you can not output a matrice of different row lengths, they have to be all the same so Excel fills the empty cells with #NA (which i hid with iferror, to match your example).

If you do want to have a row exactly the length of the quantity of values, you need to extend a different formula (a filter) manually.
 
Upvote 0
After yesterdays success of running totals in 2D arrays (Thanks Fluff), I have now hit another problem filtering the results.

I have generated a 2D array similar to the one shown below (this is a cut down version) cells O5-X14 and I'm trying to generate the two outputs AA5-AA14 and AC5-AE14. I wish to be able to use the number of filtered numbers in following equations i.e for results AC9,AD9 and AE9 there would be three different follow up equations up to a possible 10 in this example (max number of columns) so any solutions on how to also reference the filtered results would also be appreciated.

Regards

Ian

Book1
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
2
3OutputFiltered
4Column1Col1Col2Col3Col4Col5Col6Col7Col8Col9Col10Dynamic ArrayNo.s12345678910
5Row11000001000011
6Row22002000000012
7Row3690000609000269
8Row41200120000000112
9Row513413040000003134
10Row67000007000017
11Row7230002000300223
12Row800000000000
13Row915701005007003157
14Row10890008009000289
15
Sheet6
Cell Formulas
RangeFormula
O5:X14O5=Table13[[Col1]:[Col10]]
Dynamic array formulas.
Does this work for you?

Dates and Times.xlsm
NOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
1
2Output
3No,sFiltered
412345678910
5000001000011
6002000000012
70000609000269
800120000000112
913040000003134
10000007000017
110002000300223
1200000000000 
1301005007003157
140008009000289
15
Sheet8
Cell Formulas
RangeFormula
AA5:AA14AA5=IF(SUM(O5:X5)>0,COUNTIF(O5:X5,">0"),0)
AC5:AC6,AC8,AC10,AC12,AC14:AD14,AC13:AE13,AC11:AD11,AC9:AE9,AC7:AD7AC5=IF(AA5>0,TEXTSPLIT(TEXTJOIN(",",TRUE,SUBSTITUTE(O5:X5,0,"")),","),"")
 
Upvote 0
Try. In AB5
Excel Formula:
=LET(a,C5:L14,MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,IFERROR(INDEX(a,r,SMALL(IF(INDEX(a,r,)>0,COLUMN(INDEX(a,r,))-COLUMN(B4),""),c)),""))))
 
Upvote 0
Hello @HighAndWilder, i find it very clever to use the text functions as you did (way smaller formula than mine), however i think you should return the result with a VALUE(), to convert back the strings to usable numbers for future the future equations mentioned by the OP.
 
Upvote 0
Hello @HighAndWilder, i find it very clever to use the text functions as you did (way smaller formula than mine), however i think you should return the result with a VALUE(), to convert back the strings to usable numbers for future the future equations mentioned by the OP.
Good idea. I've now used a custom format of 0;-0;;@ so that the zero's don't show in the results as in the original post.

I use what I know at the time and then reverse engineer the suggestions of others to learn more. There are always many ways to skin a cat but I would never do that.

Dates and Times.xlsm
NOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
1
2Output
3No,sFiltered
412345678910
5000001000011
6002000000012
70000609000269
800120000000112
913040000003134
10000007000017
110002000300223
1200000000000 
1301005007003157
140008009000289
15
16
Sheet8
Cell Formulas
RangeFormula
AA5:AA14AA5=IF(SUM(O5:X5)>0,COUNTIF(O5:X5,">0"),0)
AC5:AC6,AC8,AC10,AC12,AC14:AD14,AC13:AE13,AC11:AD11,AC9:AE9,AC7:AD7AC5=IF(AA5>0,VALUE(TEXTSPLIT(TEXTJOIN(",",TRUE,SUBSTITUTE(O5:X5,0,"")),",")),0)
 
Upvote 0
Another possibility is to sort the data by row number using some array reshaping functions:

Excel Formula:
=LET(
    a, DROP(Table13,,1),
    b, a<>"",
    r, SEQUENCE(ROWS(a)),
    WRAPROWS(SORTBY(TOCOL(IF(b,a,"")),TOCOL(IF({1},r,a)),1,TOCOL(IF(b,r)),1),COLUMNS(a))
)

You could also omit the empty columns, if desired:

Excel Formula:
=LET(
    a, DROP(Table13,,1),
    b, a<>"",
    r, SEQUENCE(ROWS(a)),
    TAKE(WRAPROWS(SORTBY(TOCOL(IF(b,a,"")),TOCOL(IF({1},r,a)),1,TOCOL(IF(b,r)),1),COLUMNS(a)),,MAX(BYROW(a,COUNT)))
)

And if you wanted to reference the dynamic spill range (O5#) instead of Table13, the following modifications should work:

Excel Formula:
=LET(
    a, O5#,
    b, a<>0,
    r, SEQUENCE(ROWS(a)),
    TAKE(WRAPROWS(SORTBY(TOCOL(IF(b,a,"")),TOCOL(IF({1},r,a)),1,TOCOL(IF(b,r)),1),COLUMNS(a)),,MAX(BYROW(a,LAMBDA(v,COUNTIF(v,"<>0")))))
)
 
Upvote 0
REVISED: The SORTBY portion of each of the three formulas shown in my previous reply (post #7) can be simplified with a single by_array argument:
  • SORTBY(TOCOL(IF(b,a,"")),TOCOL(IF(b,r,r+0.1)))
For example, the first formula would be:

Excel Formula:
=LET(
    a, DROP(Table13,,1),
    b, a<>"",
    r, SEQUENCE(ROWS(a)),
    WRAPROWS(SORTBY(TOCOL(IF(b,a,"")),TOCOL(IF(b,r,r+0.1))),COLUMNS(a))
)
 
Upvote 0
You can simply use FILTER.
Book2
AAABACADAEAFAGAHAIAJAKAL
2Output
3No,sFiltered
412345678910
511
612
7269
8112
93134
1017
11223
120 
133157
14289
Sheet1
Cell Formulas
RangeFormula
AA5:AA14AA5=COUNTIFS(O5:X5,">0")
AC5:AC6,AC8,AC10,AC12,AC14:AD14,AC13:AE13,AC11:AD11,AC9:AE9,AC7:AD7AC5=FILTER(O5:X5,O5:X5>0,"")
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
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