How do I count consecutive same values

后端 未结 3 1565
北恋
北恋 2021-01-07 07:00

I would like formulas that count the number of consecutive occurrences in a list of values and places the amount of times it occurs in the next columns.

Here is a sp

相关标签:
3条回答
  • 2021-01-07 07:17

    I did this in long approach :)

    Assuming your data is in Column A with header (meaning actual data starts in A2).
    In B2 enter this formula and copy up to where your data extend:

    =IF(OR(A2=A3,A1=A2),"YES","NO") 'this checks if consecutive or not
    

    In C2 enter this formula and copy up to where your data extend:

    =IF(A2=A1,C1,ROW(A2)) 'this gives identity on numbers that re-occured (eg. 4 in your example)
    

    In D2 enter this formula and copy up to where your data extend:

    =COUNTIFS(A:A,A2,B:B,B2,C:C,C2) 'finally, this gives you the values that you want.
    

    Hope this helps you a bit.
    Here's the screenshot:

    enter image description here

    0 讨论(0)
  • 2021-01-07 07:20

    This will do it. It assumes your values are in A2:A11. Note that the range in the formula extends to A12. This is an array formula and needs to be entered with Ctrl-Shift-Enter. Enter it in B2 and copy down:

    =IF(A1=A2,B1,MATCH(FALSE,$A2:$A$12=A2,0)-1)
    
    0 讨论(0)
  • 2021-01-07 07:23

    The function you are looking for is countif. It will allow you to count the values in a given range.

    Count If Reference

    0 讨论(0)
提交回复
热议问题