+ Reply to Thread
Results 1 to 15 of 15

How do I count the number of consecutive 5 rows with a certain value?

  1. #1
    Registered User
    Join Date
    07-11-2019
    Location
    Nueva Ecija, Philippines
    MS-Off Ver
    2010
    Posts
    4

    How do I count the number of consecutive 5 rows with a certain value?

    Hi All,

    Thanks in advance to anyone who can help me with my problem.

    I have a dataset of rainfall from 1951 to present with values ranging from 0 to 100+.
    I want to know how many times there is a consecutive 5 days with rainfall value of less than 1.

    For example:
    Rainfall values= 0, 0, 0, 0, 0, 1.2, 0, 0, 0.2, 0.3, 0, 0.1, 0, 0.9. The answer should be 6.

    Thanks,
    Christian

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Do you mean the longest run of consecutive days that meet the criterion?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    I believe the answer should be 8:

    =MAX(FREQUENCY(IF(A1:A14<1,ROW(A1:A14)),IF(A1:A14>=1,ROW(A1:A14))))

    ... confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    This should be updated to encompass the entire range, so change each instance of this: A1:A14
    Attached Files Attached Files

  4. #4
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Hi

    Supposing your data in A2:An and using a helper column H with H1=0
    In H2 use the following formula and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The formula that count the number of consecutive 5 values less than 1 is
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Quote Originally Posted by AliGW View Post
    I believe the answer should be 8:
    ...
    I suppose both solutions are wrong and OP is also wrong.
    From A1 to A5,count 1
    From A7 to A11, 2
    From A8 to A12, 3
    From A9 to A13, 4
    From A10 to A14, 5

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Removed - misread the OP's requirements.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    José - you are right in one respect, however I think it should be two having looked again at the OP's opening post. Let's wait for clarification.

  8. #8
    Registered User
    Join Date
    07-11-2019
    Location
    Nueva Ecija, Philippines
    MS-Off Ver
    2010
    Posts
    4

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Hi AligW and Jose,

    Thank you for your answers!

    Jose, you're right. The answer should be 5.
    I want to know how may consecutive 5 days there is that have rainfall value of below 1.

    I would really appreciate it if you can give me the formula for this.

    Looking forward to your response.

    Regards,
    Christian
    Last edited by xamark_18; 07-15-2019 at 01:58 AM.

  9. #9
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Hi
    The solution with a formula, considering the data in A2: A31 can be obtained by formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    or using a helper column with this formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    you can get the same result with
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Except 1.2 all values are below 1 only. 1 to 5 and 7 to 13 are consecutive days . Count should be 2.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    I agree based on my re-reading of the requirements.

  12. #12
    Registered User
    Join Date
    07-11-2019
    Location
    Nueva Ecija, Philippines
    MS-Off Ver
    2010
    Posts
    4

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Hi kvsrinivasamurthy and Aligw,

    I am looking for the number of consecutive 5 rows that is less 1.
    From the example the answer should be 5:
    From A1 to A5, 1
    From A7 to A11, 2
    From A8 to A12, 3
    From A9 to A13, 4
    From A10 to A14, 5

  13. #13
    Registered User
    Join Date
    07-11-2019
    Location
    Nueva Ecija, Philippines
    MS-Off Ver
    2010
    Posts
    4

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Dear Jose,

    Thank you for the formula. I'm trying to check if this is correct. I put the formula on may dataset then I tried to delete some of the data to check if the answer will change.
    It changed, however instead of decreasing, the answer increased. What do you think is the explanation for this?

    Regards,
    Christian

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,930

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Please provide a workbook showing what you have tried.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

  15. #15
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How do I count the number of consecutive 5 rows with a certain value?

    Jose's formula is counting empty cells as less than 1. This one only counts the actual numbers.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create a specific number of consecutive rows based on row count input
    By goodlite in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-18-2017, 09:17 AM
  2. Count consecutive number
    By djuMSze in forum Excel General
    Replies: 4
    Last Post: 03-27-2014, 03:12 AM
  3. [SOLVED] Count number of consecutive rows of equal value?
    By Johnington in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-27-2013, 02:40 AM
  4. [SOLVED] Count number of occurrences but if there are consecutive matches count them as one
    By michaljireht in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-26-2013, 08:26 PM
  5. Replies: 4
    Last Post: 05-30-2013, 06:00 PM
  6. Replies: 0
    Last Post: 06-15-2011, 09:46 AM
  7. Function to Count Number of Consecutive Rows with a Specific Criteria?
    By Templee1 in forum Excel Formulas & Functions
    Replies: 26
    Last Post: 09-06-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1