+ Reply to Thread
Results 1 to 14 of 14

Please help me calculate the maximum consecutive negative value in a column

  1. #1
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Please help me calculate the maximum consecutive negative value in a column

    a column will have positive and negative numbers. I need to find a run of consecutive negative numbers that returns the largest combined negative value.

    attached is an example. Column A is the data. Column B is the desired output.

    Thanks!!!
    Attached Files Attached Files
    Last edited by Ocean Zhang; 03-17-2024 at 10:31 AM.

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Please help me calculate the maximum consecutive negative value in a column

    attached is an example
    sorry, no attachment
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Re: Please help me calculate the maximum consecutive negative value in a column

    sorry about that. Edited with attachment

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    One way. In B1, copied down:

    =SUM(INDEX(A:A,AGGREGATE(14,6,ROW($A$1:A1)/($A$1:A1>0),1)+1):A1)

    then =min(B:B)
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Please help me calculate the maximum consecutive negative value in a column

    these were the questions I was going to ask about different scenarios...
    1) row 17 has -1, row 18 has -1023 and row 19 has 61... what then? pull data from rows 17 and 18 - in other words find the lowest number and pull the next consecutive one above or below that is also negative?
    2) row 17 has 61, row 18 has -1023 and row 19 has 2... pull numbers from rows 11 through 15 or just pull the lowest negative # even if it is sitting alone?
    3) row 17 has -2, row 18 has -1023 and row 19 has -1 and row 20 has -57, keep pulling as long as you've found the lowest negative and include the entire consecutive sequence above and below that also contains negatives? in other words, let's say rows 11 through 22 were all negatives and -1023 was still in the mix, you want the sum of all those included?

    But Glenn's formulas take care of all those issues so I think you've got your answer.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    I'm fooling around with MMULT, trying to avoid the helper... but without success so far.

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    By ANY chance... are you using O365 yet? If so, it's easy to lose the helper column:

    =LET(A,A2:A23,B,IF(A>=0,0,A),C,DROP(VSTACK(0,B),-1),MIN(MAP(B,C,LAMBDA(y,z,IF(z=0,0,z+SUM(y))))))

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Please help me calculate the maximum consecutive negative value in a column

    Another option if you have 365
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    Yes, SCAN would be better (shorter)... but I still can't do away with the helper for Excel 2021.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Please help me calculate the maximum consecutive negative value in a column

    I still can't do away with the helper for Excel 2021.
    Nor can I, although it must be possible.

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    It is possible.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Please help me calculate the maximum consecutive negative value in a column

    Oh POOH. It doesn't work. Back to the drawing board!!!!

  13. #13
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Re: Please help me calculate the maximum consecutive negative value in a column

    Thanks guys! No problem using the helper column. Thanks!!!

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Please help me calculate the maximum consecutive negative value in a column

    Glad to help & thanks for the feedback.

+ 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. Consecutive 5 Maximum number in a column
    By ssb648 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2016, 03:12 AM
  2. Replies: 1
    Last Post: 04-14-2015, 08:34 PM
  3. [SOLVED] Find consecutive 15 positive or negative numbers in a column
    By Sarangsood in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-19-2013, 05:26 AM
  4. [SOLVED] Calculate maximum drawdown with negative numbers
    By billj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2013, 10:28 AM
  5. Replies: 8
    Last Post: 12-13-2012, 01:15 PM
  6. [SOLVED] Calculate maximum number of consecutive populated cells in a column
    By Jimbobby in forum Excel General
    Replies: 9
    Last Post: 11-11-2012, 04:24 PM
  7. Replies: 8
    Last Post: 06-26-2012, 06:45 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