+ Reply to Thread
Results 1 to 25 of 25

Count consecutive most recent values.

  1. #1
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Count consecutive most recent values.

    Hi all.

    I have tried and tried to find the answer to this, but every formula I have found doesn't seem to do exactly what I would like it to do!

    I am looking for a formula that gives me the consecutive count of the most recent value in the string, as below;

    L
    W
    W
    W
    L
    W
    L
    L
    W
    W
    W
    W

    W
    W
    W


    My problem has been the gap where there is no value, the current work around I am trying to use starts the count again after the null value.

    Any help would be great appreciated!

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Count consecutive most recent values.

    I used this formula with your wins and loses in column A and this in B1 dragged down

    I had to put an 'x' in the last row of column A so that the formula knew to stop

    Please Login or Register  to view this content.
    Its an array formula so you need to enter it by control + shift + enter

    Here's the file too so you can see it in context
    Happy with my advice? Click on the * reputation button below

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Count consecutive most recent values.

    Does this do what you need?

    =IF(A2=A1,B1+1,1)

    See the attached.
    CountWinLossStrings.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Count consecutive most recent values.

    Marvin, I think the OP wants that string of 7 Ws to show as 7 even though there is a blank row

  5. #5
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Cheers Crooza, this seems to be what I am chasing. But, the most recent value is the last, and it will add more below the last one week by week.

    Just looking over the formula to see if I can reverse it perhaps?

  6. #6
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by Crooza View Post
    Marvin, I think the OP wants that string of 7 Ws to show as 7 even though there is a blank row
    Correct. I am looking for the result of 7 to show currently.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Count consecutive most recent values.

    OK - If that is what they want then my answer is a little short (wrong) of what they need.

  8. #8
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count consecutive most recent values.

    Hi VAMH2,

    Looks like a Crows string of results to me!

    I think we need to resort to VBA! Are you happy with that?

    Please Login or Register  to view this content.
    This macro will give you the result you want. It writes the result against the last entry (in Col B).

    It could also be done as a UDF (user defined function) if you prefer.

    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  9. #9
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by David A Coop View Post
    Hi VAMH2,

    Looks like a Crows string of results to me!

    I think we need to resort to VBA! Are you happy with that?

    Please Login or Register  to view this content.
    [/COLOR][/SIZE]
    You have a very keen eye!

    I'm happy if it works.

    I change the "A" to the column that the current results show in, but it then doesn't return the result in the next column. Will this be affected in any way by a previously calculated result? An IF brings up the current column that shows the W/L results
    Last edited by VAMH2; 07-12-2016 at 01:50 AM.

  10. #10
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Count consecutive most recent values.

    Quote Originally Posted by VAMH2 View Post
    Cheers Crooza, this seems to be what I am chasing. But, the most recent value is the last, and it will add more below the last one week by week.

    Just looking over the formula to see if I can reverse it perhaps?
    Should be able to reengineer the formula to go the other way. I'll look at it when I get a chance

  11. #11
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count consecutive most recent values.

    Yes, changing the A to whatever the column is will work. It is looking for the last row where you have an entry.

    However, you will need to edit one more thing. In the Cells() formulas, the second parameter is referring to the column.

    I used 1 because it was easier to type than "A". Therefore, you can change these to the column number if you like, or the letter.

    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  12. #12
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by David A Coop View Post
    I hope this helps, please let me know![/COLOR][/SIZE]
    Still not 100%. I am using Column "AK", results will show up in Rows 4-30. When IF returns no results, I'm currently using "".

    Thanks.

  13. #13
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count consecutive most recent values.

    Have adjusted for use of column AK.

    Please Login or Register  to view this content.
    You will now the answer next to the last entry in Col AL

    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  14. #14
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by David A Coop View Post
    I hope this helps, please let me know!
    Doesn't look like this is going to work.

    I have just run some testing, and it seems because it is referencing a result from an IF statement, it doesn't pick up on it. Running it from a blank worksheet and just putting in the data manually it picks it up straight away.

    Thanks for the help, but think it may only work with a formula, got too much going on for it to rely on VB it seems. Will see if Crooza was able to reverse what he did, as it seems like that just may work for me.

    Cheers.

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

    Re: Count consecutive most recent values.

    Try this...

    Data Range
    A
    B
    C
    1
    Won/Loss
    ------
    Streak
    2
    L
    7 W
    3
    W
    4
    W
    5
    W
    6
    L
    7
    W
    8
    L
    9
    L
    10
    W
    11
    W
    12
    W
    13
    W
    14
    15
    W
    16
    W
    17
    W
    18


    This array formula** entered in C2:

    =LOOKUP(1E100,FREQUENCY(IF(A2:A100=LOOKUP("zzz",A2:A100),ROW(A2:A100)),
    IF(A2:A100<>LOOKUP("zzz",A2:A100),IF(A2:A100<>"",ROW(A2:A100)))))
    &" "&LOOKUP("zzz",A2:A100)

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  16. #16
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by Tony Valko View Post
    Try this...
    Thanks for that. Currently it is returning a value of '81' (81 blank cells after last result). If I change the data to rows 4-30 where values appear, it returns '11' (empty cells after last result).

    It seems that because the cells with no results are gathered by an IF statement, it still counts them as there is something in there.

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

    Re: Count consecutive most recent values.

    There's always some detail that gets left out!

    Well, that makes things a lot more complicated.

    Create a dynamic named range.

    Goto the formulas tab>Define name

    Name: Range
    Refers to:

    =OFFSET($A$2,,,MAX(IF($A$2:$A$100<>"",ROW($A$2:$A$100)))-1)

    Then, the formula becomes:

    =LOOKUP(1E100,FREQUENCY(IF(Range=LOOKUP("zzz",Range),ROW(Range)),
    IF(Range<>LOOKUP("zzz",Range),IF(Range<>"",ROW(Range)))))
    &" "&LOOKUP("zzz",Range)

    Still array entered.

    Here's a sample file that demonstrates this.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    03-27-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Count consecutive most recent values.

    Quote Originally Posted by Tony Valko View Post
    There's always some detail that gets left out!
    Originally I had forgotten to add that detail, but was mentioned a couple posts in. Anyway...

    Success!

    Awesome, thanks for the help. Been bugging me for ages, and just as 1 thing seemed to have worked the next minute it wasn't.

    Thanks all in the thread for helping/trying.

  19. #19
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count consecutive most recent values.

    Quote Originally Posted by VAMH2 View Post
    Doesn't look like this is going to work.
    Sorry to hear that. I guess I would have to see the workbook to test it myself.

    I see Tony has come up with an amazing formula! I knew that it would be an ARRAY formula, but too cleaver for me! (That's why he's a guru!) I'm going to unpack it to see how it works!

    All the best.

    David (a hopeful Demon supporter)

  20. #20
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Count consecutive most recent values.

    Just turn mine around like this to count in the opposite direction

    Please Login or Register  to view this content.
    Last edited by Crooza; 07-12-2016 at 10:39 PM. Reason: small edit to formula

  21. #21
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Count consecutive most recent values.

    I received some inspiration from Tony when he suggested using OFFSET to get the dynamic range name.

    Here is another formula:

    =COUNTA(INDIRECT("A"&MAX(ROW(1:200)*(A1:A200=IF(INDIRECT("A"&(ROWS(OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1))))="W","L","W")))+1&":A"&ROWS(OFFSET($A$1,0,0,MATCH("*",$A:$A,-1),1))))

    THIS IS AN ARRAY FORMULA

    Probably too late to try since you have something that works, but I couldn't get my head around Tony's formula, so was determined to try something...

    Best wishes!

    David

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

    Re: Count consecutive most recent values.

    You're welcome. Thanks for the feedback!

  23. #23
    Registered User
    Join Date
    04-09-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    6

    Re: Count consecutive most recent values.

    Quote Originally Posted by Tony Valko View Post
    Try this...

    Data Range
    A
    B
    C
    1
    Won/Loss
    ------
    Streak
    2
    L
    7 W
    3
    W
    4
    W
    5
    W
    6
    L
    7
    W
    8
    L
    9
    L
    10
    W
    11
    W
    12
    W
    13
    W
    14
    15
    W
    16
    W
    17
    W
    18


    This array formula** entered in C2:

    =LOOKUP(1E100,FREQUENCY(IF(A2:A100=LOOKUP("zzz",A2:A100),ROW(A2:A100)),
    IF(A2:A100<>LOOKUP("zzz",A2:A100),IF(A2:A100<>"",ROW(A2:A100)))))
    &" "&LOOKUP("zzz",A2:A100)

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Hi Tony, I notice this is an older post, but hopefully you'll see this...The above array works great for what I need it to do, but is there any way to make it return W7 instead of 7 W (7"space"W)? I tried to manipulate it, but don't really understand how it works and couldn't make it happen.

  24. #24
    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
    81,122

    Re: Count consecutive most recent values.

    Try this:

    =LOOKUP("zzz",A2:A100)&LOOKUP(1E100,FREQUENCY(IF(A2:A100=LOOKUP("zzz",A2:A100),ROW(A2:A100)),IF(A2:A100<>LOOKUP("zzz",A2:A100),IF(A2:A100<>"",ROW(A2:A100)))))
    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.

  25. #25
    Registered User
    Join Date
    04-09-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    6

    Re: Count consecutive most recent values.

    Quote Originally Posted by AliGW View Post
    Try this:

    =LOOKUP("zzz",A2:A100)&LOOKUP(1E100,FREQUENCY(IF(A2:A100=LOOKUP("zzz",A2:A100),ROW(A2:A100)),IF(A2:A100<>LOOKUP("zzz",A2:A100),IF(A2:A100<>"",ROW(A2:A100)))))
    Works perfectly, thank you very much! I'm new to the forum and didn't realize I should have started a new thread for this. Will do next time!

+ 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 of Values (Rows) of Most Recent Consecutive Streak (2+ Distinct Values)
    By ExcelForum88 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-13-2016, 12:26 PM
  2. [SOLVED] Count most recent 12 values in a column that are >0 when values are added monthly
    By Phillycheese5 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-03-2014, 04:31 PM
  3. Count non-consecutive values
    By Kerrigan7 in forum Excel General
    Replies: 2
    Last Post: 11-10-2011, 09:34 AM
  4. Count First set of Consecutive Values
    By sushi637 in forum Excel General
    Replies: 3
    Last Post: 05-19-2010, 03:05 PM
  5. Count Consecutive Values
    By roberto1111 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-05-2010, 05:33 AM
  6. Count Consecutive Values
    By roberto1111 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2009, 03:06 AM
  7. [SOLVED] Count Intervals of 2 Consecutive Values in same Row and Return Count across Row
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-29-2005, 11:30 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