+ Reply to Thread
Results 1 to 18 of 18

Formula to count number of consecutive values in previous cells

  1. #1
    Registered User
    Join Date
    09-06-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Formula to count number of consecutive values in previous cells

    Hi Guys,

    First post here. I'd like to find a formula (VBA is not an option in this case) to find the current "streak" of zero-defect weeks in a list of quality data. The data is organized into a fiscal week column and a quality defects column (0 being good).

    How can I count, for the current fiscal week (last populated cell), how long the streak has been since the last quality defect? I don't want to add an extra column for running up a cumulative streak, I only have one cell available to me to do a streak calculation for the most recent week.

    Any ideas??
    Attached Images Attached Images

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    Hi,

    Sure they'll be a simpler (and non-array) solution, but this array formula in E2 (I think? Based on your screenshot at least) and copied down:

    =IF(B2>0,0,MATCH(TRUE,N(OFFSET(B2,-ROW(INDIRECT("1:"&ROWS($1:1))),,,))<>0,0))

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    05-23-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Formula to count number of consecutive values in previous cells

    Eschmidt, welcome to the forum

    I believe I have solved this for you in a non-array formula:

    In the first cell enter: =IF(B2>0,0,1)
    In the rest of the cells enter: =IF(B3>0,0,IF(D2>0,D2+1,1))

    The column structure I used was Fiscal Week -> Quality Escapes ->Cumulative -> New Formula
    Last edited by kelleytr; 09-06-2013 at 04:19 PM.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    @kelleytr

    Looks nice, only...you appear to be referencing a column D in your formula? Is this the Streak column given in the screenshot? If so, isn't that the very column which was given by the OP as their desired results and which we should be re-creating?

    Regards

  5. #5
    Registered User
    Join Date
    09-06-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Formula to count number of consecutive values in previous cells

    XOR LX - I think that you're on the right track, but I'm getting a #N/A return from the cells that have a zero in the quality escapes column. Any idea what to adjust in the formula? Am I correct in that this formula will stand alone, i.e. it does not depend on incrementing a cumulative streak column?

    Kelleytr, thanks for your solution, but I'm hoping to be able to perform this calculation in just one cell. I used the same exact formula to generate the sample spreadsheet

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count number of consecutive values in previous cells

    What exactly do you want to count? Is it the count of consecutive 0s at the bottom of column D?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    Works fine for me. Are you absolutely sure you heeded my advice to enter it as an array formula?

    Regards

  8. #8
    Registered User
    Join Date
    09-06-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Formula to count number of consecutive values in previous cells

    No, I'd like to count the number of consecutive zeros in col B, but only for the last FW. I only have one cell in which to do the calculation, I cannot add a new column to do a cumulative increment.

    For example, the result for FW14 would be zero, because there were 6 quality escapes that week. However if only up through FW9 was populated, the result would be 3, becausee each of FW's 7, 8, and 9 are zeros.

  9. #9
    Registered User
    Join Date
    09-06-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Formula to count number of consecutive values in previous cells

    That was it! Thanks!!!

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Formula to count number of consecutive values in previous cells

    OK, looks like you have a solution.

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    Er, not so sure now that you've added further comments.

    The formula I gave you was designed to be dragged down to give the respective results for the entries in the Quality Escapes column, not simply a one-off formula to give the result for the last entry in that column. If you need to do that, you'll need something like this array:

    =IF(INDEX($B:$B,MATCH(REPT("z",255),$A:$A))>0,0,MATCH(TRUE,N(OFFSET(INDEX($B:$B,MATCH(REPT("z",255),$A:$A)),-ROW(INDIRECT("1:"&MATCH(REPT("z",255),$A:$A)-2)),,,))<>0,0))

    Regards

  12. #12
    Registered User
    Join Date
    05-23-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Formula to count number of consecutive values in previous cells

    Quote Originally Posted by XOR LX View Post
    @kelleytr

    Looks nice, only...you appear to be referencing a column D in your formula? Is this the Streak column given in the screenshot? If so, isn't that the very column which was given by the OP as their desired results and which we should be re-creating?

    Regards
    Yes, it does reference column D however it is utilizing the cell above it. As the formula goes down it is referencing a previous calculation above it within the same column.

  13. #13
    Registered User
    Join Date
    05-23-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Formula to count number of consecutive values in previous cells

    Quote Originally Posted by eschmidt12 View Post
    XOR LX - I think that you're on the right track, but I'm getting a #N/A return from the cells that have a zero in the quality escapes column. Any idea what to adjust in the formula? Am I correct in that this formula will stand alone, i.e. it does not depend on incrementing a cumulative streak column?

    Kelleytr, thanks for your solution, but I'm hoping to be able to perform this calculation in just one cell. I used the same exact formula to generate the sample spreadsheet
    Are you sure? I didn't use the cumulative column and I believe you did. For my formula to work all you need is the quality escapes. The rest of it references itself within the column.

    Assuming this isn't too many columns (fiscal weeks) it should be fine with an array formula. If it was over several thousand rows I would suggest my formula as an alternative.

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    @kelleytr

    My apologies for misunderstanding and congratulations on a non-array solution.

    It now appears (though I'm still not entirely sure!) that the OP is actually wanting something different to that which we both thought, i.e. a single-cell formula to give just the result for the last entry...

    Regards

  15. #15
    Registered User
    Join Date
    05-23-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Formula to count number of consecutive values in previous cells

    Thanks Xor, I read his previous post also and I am not entirely sure what he means either. Since he said "That was it" earlier I believe he found what he was looking for.

    Nice array formulas by the way. I'm still getting use to them but I know they can accomplish wonders!

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Formula to count number of consecutive values in previous cells

    Actually I tend to overuse them! And am grateful for the likes of yourself who have the ingenuity to come up with non-array solutions.

    Cheers

  17. #17
    Registered User
    Join Date
    09-06-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Formula to count number of consecutive values in previous cells

    Hey - sorry about the confusion...I was replying as fast as I could but I still wasn't as quick as you guys XOR LX, what I mean by "that was it" was that I had forgotten to enter your formula as an array. Once I entered it as an array, it worked exactly as I needed! Once I get back to work on Monday I'll try the other array formula that you suggested, it'll be great if that works.

    kelleytr - yours is still a great solution (and is the one I used to generate the streak column), but does require an extra column. In my sample I had the cumulative column there just for reference. I had also used the >0 criteria as my "reset" for the incremental count for the streak.

  18. #18
    Registered User
    Join Date
    04-26-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Formula to count number of consecutive values in previous cells

    I need to make this formula work as well. However if cell B2 is 0, I also get #N/A returned. I did enter the formula "=IF(B2>0,0,MATCH(TRUE,N(OFFSET(B2,-ROW(INDIRECT("1:"&ROWS($1:1))),,,))<>0,0))" as an array. I need some help.

+ 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. count the number of consecutive values >=2
    By jomuir in forum Excel General
    Replies: 8
    Last Post: 03-03-2017, 12:59 PM
  2. Replies: 2
    Last Post: 07-25-2013, 01:01 PM
  3. Count number of consecutive cells
    By skullte in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-07-2013, 03:20 AM
  4. Replies: 0
    Last Post: 06-15-2011, 09:46 AM
  5. Replies: 2
    Last Post: 09-01-2010, 07:48 AM

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