Answer the question
In order to leave comments, you need to log in
How to count the maximum number of identical values in a row in a column?
How to count the maximum number of identical values in a row in a column? Preferably in Sheets, but it’s also possible in Excel, it’s important for me to understand the principle in general, since I didn’t find anything on the Internet, and I myself am new to tables
There is a column with certain values, for certain reasons we are interested in series of identical values in a row, and specifically the maximum series , thus it is necessary that the formula finds series and among them determines the largest for a particular value. In the picture, I think it is clear what we need. Please someone tell me how to implement this
Answer the question
In order to leave comments, you need to log in
=MAX(ARRAYFORMULA(LEN(SPLIT(JOIN("",FILTER(--(A:A = "cat"),A:A<>"")),"0"))))
=MAX(ARRAYFORMULA(LEN(SPLIT(JOIN("",FILTER(--(A:A = "dog"),A:A<>"")),"0"))))
For such a task, some kind of complex solution is expected, since search solely by the condition of the occurrence of an element somewhat detracts from the advantages of tabular calculations.
For custom function
/**
* Returns a consecutive array of the counts of sequences.
*
* @param {Sheet3!B1:B34} reference A range.
* @returns The counts of sequences.
* @customfunction
*/
function COUNT_CONSECUTIVE( reference ){
try{
return reference.reduce(function(p, v, i, arr){
if(i === 0 || arr[i][0] !== arr[i - 1][0])
p.push([v[0], 1]);
else
p[p.length-1][1]++;
return p;
}, []);
} catch(err){
return err.message
}
}
A2:A10
it is true that all groups without numbers with their quantities can be obtained as =COUNT_CONSECUTIVE(A2:A10)
'cat'
true=QUERY(COUNT_CONSECUTIVE(A2:A9),"select max(Col2) where Col1='cat' label max(Col2)''")
=ARRAYFORMULA(QUERY({A2:A10,VLOOKUP(ROW(A2:A10),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)>0,{ROW(A2:A10),IF(A2:A10<>A1:A9,ROW(A2:A10),0)},),2),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)=0, COUNTIFS(ROW(A2:A10),">=" & VLOOKUP(ROW(A2:A10),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)>0,{ROW(A2:A10),IF(A2:A10<>A1:A9,ROW(A2:A10),0)},),2),ROW(A2:A10),"<="&ROW(A2:A10)),1)},"select Col1,max(Col3) group by Col2,Col1 label max(Col3)''"))
A2:A10
it is true that all groups without numbers with their quantities can be obtained as 'cat'
true=ARRAYFORMULA(QUERY(QUERY({A2:A10,VLOOKUP(ROW(A2:A10),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)>0,{ROW(A2:A10),IF(A2:A10<>A1:A9,ROW(A2:A10),0)},),2),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)=0, COUNTIFS(ROW(A2:A10),">=" & VLOOKUP(ROW(A2:A10),IF(IF(A2:A10<>A1:A9,ROW(A2:A10),0)>0,{ROW(A2:A10),IF(A2:A10<>A1:A9,ROW(A2:A10),0)},),2),ROW(A2:A10),"<="&ROW(A2:A10)),1)},"select Col1,max(Col3) group by Col2,Col1 label max(Col3)''"),"select max(Col2) where Col1='cat' group by Col1 label max(Col2)''"))
'cat'
, it is also true=ARRAYFORMULA(MAX(FREQUENCY(ROW(A2:A10),ROW(A2:A10)*(A2:A10<>"cat")))-1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question