K
K
kushekpayev2019-09-03 23:44:55
excel
kushekpayev, 2019-09-03 23:44:55

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 this5d6ed0ac3e544122035789.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2019-09-04
@kushekpayev

=MAX(ARRAYFORMULA(LEN(SPLIT(JOIN("",FILTER(--(A:A = "cat"),A:A<>"")),"0"))))
=MAX(ARRAYFORMULA(LEN(SPLIT(JOIN("",FILTER(--(A:A = "dog"),A:A<>"")),"0"))))

A
Alexander Ivanov, 2019-09-08
@oshliaer

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
  }
}

for a range A2:A10it is true that all groups without numbers with their quantities can be obtained as
=COUNT_CONSECUTIVE(A2:A10)
5d754c49274da817053940.png
soon as for 'cat'true
=QUERY(COUNT_CONSECUTIVE(A2:A9),"select max(Col2) where Col1='cat' label max(Col2)''")

5d754d8f60f86173403213.png
For formula
=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)''"))

for a range A2:A10it is true that all groups without numbers with their quantities can be obtained as
5d754e79dee57726785964.png
soon as for '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)''"))

5d754f0873110194817762.png
I'll post an example table soon.
PS Knowledgeable people suggest that for a particular value 'cat', it is also true
=ARRAYFORMULA(MAX(FREQUENCY(ROW(A2:A10),ROW(A2:A10)*(A2:A10<>"cat")))-1)

5d764d5082050857795309.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question