Compact the formula instead of repeating

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,180
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Is there a better way to do this than repeating with a dynamic array? Thanks in advance!

=HSTACK(
COUNTIF($B$2:$B$7,SEQUENCE(10)),
COUNTIF($C$2:$C$7,SEQUENCE(10)),
COUNTIF($D$2:$D$7,SEQUENCE(10)),
COUNTIF($E$2:$E$7,SEQUENCE(10)),
COUNTIF($F$2:$F$7,SEQUENCE(10))
)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe something like this?

Excel Formula:
=LET(
a,B2:F7,
b,COLUMNS(a),
WRAPROWS(BYROW(WRAPROWS(TOCOL(--(SEQUENCE(10)=TOROW(a,,TRUE))),b),SUM),b))
 
Upvote 0
Maybe this:
Book2
BCDEFGHIJKL
1
23648300010
331047000010
49591020001
567106410202
64652601110
70695413011
801010
900010
1010200
1101100
Sheet3
Cell Formulas
RangeFormula
H2:L11H2=MAKEARRAY(10,COLUMNS(B2:F7),LAMBDA(r,c,COUNTIF(INDEX(B2:F7,0,c),r)))
Dynamic array formulas.
 
Upvote 0
Cubist that is it!!!! Sorry, I should have posted the data with the question. Thank you so much!!!

Contestantjudge 1judge 2judge 3judge 4judge 5
Joe101010109
PJ1099910
Tom91091010
Sue10910109
Sally1010101010
Billy10981010


Answer that I am looking for

00000
00000
00000
00000
00000
00000
00000
00100
13212
53354
 
Upvote 0
You're welcome. Glad we can assist.
 
Upvote 0
Maybe something like this?
Excel Formula:
=LET(a,B2:F7,b,COLUMNS(a),WRAPROWS(BYROW(WRAPROWS(TOCOL(--(SEQUENCE(10)=TOROW(a,,TRUE))),b),SUM),b))

Nice concept! The only misstep was the wrap_count argument of the nested WRAPROWS function. ;) It should be ROWS(a):

Excel Formula:
=LET(a,B2:F7,WRAPROWS(BYROW(WRAPROWS(TOCOL(--(SEQUENCE(10)=TOROW(a,,1))),ROWS(a)),SUM),COLUMNS(a)))

MMULT could also work:

Excel Formula:
=MMULT(--(TOROW(B2:F7)=SEQUENCE(10)),--(TOCOL(IF({1},B1:F1,B2:F7))=B1:F1))

Or, if the column headers in B1:F1 were either not present or not unique:

Excel Formula:
=LET(a,B2:F7,c,SEQUENCE(,COLUMNS(a)),MMULT(--(TOROW(a)=SEQUENCE(10)),--(TOCOL(IF({1},c,a))=c)))

Of course there's also REDUCE:

Excel Formula:
=LET(n,SEQUENCE(10),REDUCE(n,SEQUENCE(COLUMNS(B2:F7)),LAMBDA(a,c,HSTACK(a,COUNTIF(INDEX(B2:F7,,c),n)))))

Or with THUNKS instead of INDEX:

Excel Formula:
=LET(n,SEQUENCE(10),REDUCE(n,BYCOL(B2:F7,LAMBDA(c,LET(x,COUNTIF(c,n),LAMBDA(x)))),LAMBDA(a,λ,HSTACK(a,λ()))))

Cheers!
 
Last edited:
Upvote 0
Nice concept! The only misstep was the wrap_count argument of the nested WRAPROWS function. ;) It should be ROWS(a):

Excel Formula:
=LET(a,B2:F7,WRAPROWS(BYROW(WRAPROWS(TOCOL(--(SEQUENCE(10)=TOROW(a,,1))),ROWS(a)),SUM),COLUMNS(a)))

MMULT could also work:

Excel Formula:
=MMULT(--(TOROW(B2:F7)=SEQUENCE(10)),--(TOCOL(IF({1},B1:F1,B2:F7))=B1:F1))

Or, if the column headers in B1:F1 were either not present or not unique:

Excel Formula:
=LET(a,B2:F7,c,SEQUENCE(,COLUMNS(a)),MMULT(--(TOROW(a)=SEQUENCE(10)),--(TOCOL(IF({1},c,a))=c)))

Of course there's also REDUCE:

Excel Formula:
=LET(n,SEQUENCE(10),REDUCE(n,SEQUENCE(COLUMNS(B2:F7)),LAMBDA(a,c,HSTACK(a,COUNTIF(INDEX(B2:F7,,c),n)))))

Or with THUNKS instead of INDEX:

Excel Formula:
=LET(n,SEQUENCE(10),REDUCE(n,BYCOL(B2:F7,LAMBDA(c,LET(x,COUNTIF(c,n),LAMBDA(x)))),LAMBDA(a,λ,HSTACK(a,λ()))))

Cheers!

Many thanks for the correction, @djclements! The concept was of course inspired by your previous posts which I try to follow closely; the same goes for @Cubist as I learn something new from both of you...
 
Upvote 0
Thanks to everyone for helping and sharing your knowledge. I appreciate it!
 
Upvote 0

Forum statistics

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