counting combinations of 3's

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
546
Office Version
  1. 365
Platform
  1. Windows
hi, i got help here Excel Questions
regarding counting combinations of 2's,
now i need to do so for 3's, and 4's,
can someone help me modify it?
Excel Formula:
=LET(t,TOCOL(C2:H3),SUM(--(DROP(t,-1)&"-"&DROP(t,1)=C1:G1&"-"&D1:H1)))
and maybe explain it to me in a few words?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi excelNewbie22,

Do you have an example of data so we could better understand the problem?

Thanks,

Vincent
 
Upvote 0
didn't noticed for posting the wrong link

any how... i need the q2 result in one formula like in the post above with no helpers columns, and also same for repeating of 4's
sample:
149.xlsm
CDEFGHIJKLMNOPQ
1SUM
2246810122-4-64-6-86-8-108-10-1211002
312468401-2-42-4-64-6-86-8-40
12
Cell Formulas
RangeFormula
I2:L3I2=C2&"-"&D2&"-"&E2
M2M2=COUNTIF(I3:L4,I2)
N2N2=COUNTIF(I3:L4,J2)
O2O2=COUNTIF(I3:L4,K2)
P2P2=COUNTIF(I3:L4,L2)
Q2Q2=SUM(M2:P2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M2:P2,T5:W2023,M4:P4Cell Value=2textNO
M2:P2,T5:W2024,M4:P4Cell Value=1textNO
 
Upvote 0
Hi,

If you consider column "I:L" as helper, then I will need some more time to think about it.

If not, here's how I would do it:
- for each row of column "I", I would add the following formula with addapted range (C2:H2) and the number of combination elements (3) :
Excel Formula:
=LAMBDA(rowToConcat,groupSize,BYCOL(SEQUENCE(1,COLUMNS(rowToConcat)-groupSize+1,1,1),LAMBDA(c,TEXTJOIN("-",TRUE,CHOOSECOLS(rowToConcat,SEQUENCE(groupSize,1,MAX(c),1))))))(C2:H2,3)

- In the cell where you want the sum of duplication and change the range to fit the data obtained by the previous step:
Excel Formula:
=LAMBDA(tbl,SUM(BYROW(UNIQUE(TOCOL(tbl)),LAMBDA(r,COUNTIF(tbl,r)-1))))(I2:L4)

Let me know if something need to be changed.

Vincent
 
Upvote 0
Hi excelNewbie22,

Here's my new try, you just have to change "groupSize" (3) for the value that you need (3's), and "tbl" for the range with the number.

-English- *I have the french version of Excel, the formula might not be exact in english due to manual translation*
Excel Formula:
=LET(groupSize,3,
tbl,C8:H11,
possibleOptionsFunction,LAMBDA(rowToConcat,groupSize,TEXTJOIN(";",TRUE,BYCOL(SEQUENCE(1,COLUMNS(rowToConcat)-groupSize+1,1,1),LAMBDA(c,TEXTJOIN("-",TRUE,CHOOSECOLS(rowToConcat,SEQUENCE(groupSize,1,MAX(c),1))))))),
allPossibilities,TEXTSPLIT(TEXTJOIN(";",TRUE,BYROW(tbl,LAMBDA(r,possibleOptionsFunction(r,groupSize)))),,";",TRUE),
uniquePossib,UNIQUE(allPossibilities),
SUM(BYROW(uniquePossib,LAMBDA(r,ROWS(FILTER(allPossibilities,allPossibilities=r,""))-1))))

-French-
Excel Formula:
=LET(groupSize;3;
tbl;C8:H11;
possibleOptionsFunction;LAMBDA(rowToConcat;groupSize;JOINDRE.TEXTE(";";VRAI;BYCOL(SEQUENCE(1;COLONNES(rowToConcat)-groupSize+1;1;1);LAMBDA(c;JOINDRE.TEXTE("-";VRAI;CHOISIRCOLS(rowToConcat;SEQUENCE(groupSize;1;MAX(c);1)))))));
allPossibilities;FRACTIONNER.TEXTE(JOINDRE.TEXTE(";";VRAI;BYROW(tbl;LAMBDA(r;possibleOptionsFunction(r;groupSize))));;";";VRAI);
uniquePossib;UNIQUE(allPossibilities);
SOMME(BYROW(uniquePossib;LAMBDA(r;LIGNES(FILTRE(allPossibilities;allPossibilities=r;""))-1))))

Bests regards,

Vincent
 
Last edited:
Upvote 0
thanks vincent, but several things don't working out for me, i'll try explaining with a sample

Cell Formulas
RangeFormula
I167:L173I167=C167&"-"&D167&"-"&E167
M167:M173M167=COUNTIF(I168:L173,I167)
N167:N173N167=COUNTIF(I168:L173,J167)
O167:O173O167=COUNTIF(I168:L173,K167)
P167:P173P167=COUNTIF(I168:L173,L167)
Q167:Q173Q167=SUM(M167:P167)
R167:R173R167=LET(groupSize,3, tbl,C167:H172, possibleOptionsFunction,LAMBDA(rowToConcat,groupSize,TEXTJOIN(";",TRUE,BYCOL(SEQUENCE(1,COLUMNS(rowToConcat)-groupSize+1,1,1),LAMBDA(c,TEXTJOIN("-",TRUE,CHOOSECOLS(rowToConcat,SEQUENCE(groupSize,1,MAX(c),1))))))), allPossibilities,TEXTSPLIT(TEXTJOIN(";",TRUE,BYROW(tbl,LAMBDA(r,possibleOptionsFunction(r,groupSize)))),,";",TRUE), uniquePossib,UNIQUE(allPossibilities), SUM(BYROW(uniquePossib,LAMBDA(r,ROWS(FILTER(allPossibilities,allPossibilities=r,""))-1))))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M:PCell Value>0textNO
Q:RCell Value>0textNO


first thing, i need the formula to point to 2 ranges, one point for the test row (like c167:h167) agains the the second range c168:h173, cause going forward i'll need the change 1 of the two ranges,

second, in R167 it says i have one duplicate, which i really don't, like i show in m167: p167 which is the long way, with helpers, for this formula

third, and i know i can't really ask for it, but i'll try, is there a chance for a shorter formula? i'm intending to run it for like a million rows (testing data)
 
Upvote 0
Hi,

1- When you said you need "one for all" formula, what does it mean if not calculate all double values?
2- What is the test row? Is it like the values you want to find in the million rows where you write multiple number (eg. 1,3,4,5) or multiple 3's and 4's (eg. 1-3-4,3-4-5,...)?
3- R167 is right, it looks if there is double values in the range (C167:H172) and you have 8-9-19 from C-D-E171 and D-E-F172. What is wrong here and what is supposed to be the correct answer?
4- I will try but i think i'm lost in your project sorry

Thanks for the precision,

Vincent
 
Upvote 0
Helper columns M,N,O,P can be avoided using only these two spill out formulas.
In I167
Excel Formula:
=LET(a,C167:H173,MAKEARRAY(ROWS(a),COLUMNS(a)-2,LAMBDA(r,c,INDEX(a,r,c)&"-"&INDEX(a,r,c+1)&"-"&INDEX(a,r,c+2))))
In Q167
Excel Formula:
=MAP(I167:I173,I168:I174,L167:L173,LAMBDA(a,b,c,SUM(COUNTIF(b:L173,a:c))))
 
Upvote 0
kvsrinivasamurthy, thank you, i liked the first formula, but still, i'm looking for one formula, that is, if it's possible (like the sample in post # 1)

vincent,
1- i meant without any helper columns
2-test row will be in seperate column, like say, $c$1:$h$1 (i.e 1-20-30-35-55-79)
BUT for now i'm testing one row against the 6 rows after, like in the sample above
3-you right, but it isn't what i ask, R167 is checking for doubles (of 3's) in range C167:H172, but i asked for finding doubles from C166:H166
4-no need for sorry, you just trying to help, and i appreciate it
 
Upvote 0

Forum statistics

Threads
1,225,350
Messages
6,184,445
Members
453,233
Latest member
bgmb

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