+ Reply to Thread
Results 1 to 12 of 12

Combine negative number with the number in cell next to it until the sum becomes positive

  1. #1
    Registered User
    Join Date
    06-05-2017
    Location
    Kuala Lumpur
    MS-Off Ver
    2007
    Posts
    3

    Combine negative number with the number in cell next to it until the sum becomes positive

    I need to have a formula that i can put in each cell in row 2 below, that will return the value in the cell above it - if the number above it (row 1) is positive.
    However, if the cell above it (row1) is negative, I need to return 0 in cell row 2, and cumulate-sum the negative number in row 1 with number next to it and so on, until I get a positive amount from the temporary sum and display this in row 2.

    In short, cells in row 2 cannot be negative, but the total in row 2 should still be = total in row 1.

    Row 1: 0 2 -3 2 5 -2 3
    Row 2: 0 2 0 0 4 0 1


    was thinking an array formula, but not sure how.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    in A2
    =MAX(A1,0)

    will give you a positive number of the row above or 0 if its negative

    "cumulate-sum"

    Not n English word so i dont understand what your after from this point.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Nevermind, need to redo formula!

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Maybe this in A2 and filled right

    =MAX(0,SUM($A1:A1))

  5. #5
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Back with one that I think works:

    NOTE: You will need to have start from column B or later. Not sure how to fix so that REF!# errors don't propagate down if pasted into column A and formula is dragged across (since there's no column left of A).

    =IF(COLUMN(B1)=2,B1,MAX(SUM(A1:$B1)-SUM(A2:$B2)+B1,0))

    When dragged across, column D formula becomes:

    =IF(COLUMN(D1)=2,D1,MAX(SUM($B1:C1)-SUM($B2:C2)+D1,0))
    Last edited by Monimonika; 06-05-2017 at 03:42 PM.

  6. #6
    Registered User
    Join Date
    06-05-2017
    Location
    Kuala Lumpur
    MS-Off Ver
    2007
    Posts
    3

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Thank you Monimonika and Jonmo and Special K,
    the last formula from Monimonika worked for the sample given. However when I changed the combination such as below, it didnt return result in
    row 2 correctly

    0 -1 0 0 0 2 3 data
    0 -1 0 0 0 2 3 result using monika formula
    0 -1 0 0 0 1 4 expected result

    The 7th column is 1 because -1+0+0+0+2 = 1.

    I guess it will just require a bit more tweaking of the current proposed formula.

    for special K, cumulate -sum i meant as cumulative sum. Basically I need to group the cells in row 1 together with the next additional columns, until my cumulative sum starting from where the column shows negative amount becomes a positive amount when combined with the cell(s) to its right and display that positive amount in the last column of the cumulative columns.

  7. #7
    Registered User
    Join Date
    06-05-2017
    Location
    Kuala Lumpur
    MS-Off Ver
    2007
    Posts
    3

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    ow n i don't mind adding new columns/rows/ use additional helper rows/columns if that solves the problem.
    Thanks.

  8. #8
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Duplicated post

  9. #9
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    0 -1 0 0 0 1 4 expected result

    Hi iniakupake01,

    Can I know why the 2nd result is -1?


    and,
    I believe Jonmo1 formula is good enough.

    Can you use the Jonmo1's formula?

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    I don't understand how you got your expected results in your first example.
    But this definately provides the expected results of your 2nd example
    =MAX(0,SUM($A1:A1))
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    With the exception of the -1 in the 2nd position in example 2 (I thought negative values were brought to 0?) this formula works for both examples

    =MAX(0,SUM(INDEX($A$1:A$1,IFERROR(LOOKUP(2,1/($A$1:A$1<0),COLUMN($A$1:A$1)),1)):INDEX($A$1:A$1,COLUMN(A$1))))

    I believe that the OP is restarting the summation when a negative value is encountered. This accounts for both examples (except for that negative 1 which I think is an error)
    Attached Files Attached Files
    Last edited by ChemistB; 06-06-2017 at 09:24 AM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  12. #12
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Combine negative number with the number in cell next to it until the sum becomes posit

    Quote Originally Posted by iniakupake01 View Post
    However, if the cell above it (row1) is negative, I need to return 0 in cell row 2, and cumulate-sum the negative number in row 1 with number next to it and so on, until I get a positive amount from the temporary sum and display this in row 2.
    0 -1 0 0 0 2 3 data
    0 -1 0 0 0 2 3 result using monika formula
    0 -1 0 0 0 1 4 expected result
    The OP is contradicting themselves on what they want (why is a -1 expected in row 2???)
    Also, my results are as follows:

    0 -1 0 0 0 2 3 row 1 data
    0 0 0 0 0 1 3 row 2 result

    The first row of data should start at cell B1 for my formula to work.
    There is NO WAY for my formula to result in a negative number, so the OP is pasting stuff wrong.

    EDIT: I'm an idiot. I forgot to account for if B1 is negative, so of course a negative number is possible. Doh!
    Corrected formula (might want to check on the formulas from others):

    =IF(COLUMN(B1)=2,IF(B1>0,B1,0),MAX(SUM(A1:$B1)-SUM(A2:$B2)+B1,0))
    Last edited by Monimonika; 06-06-2017 at 11:12 AM. Reason: Realized own mistake in orginal formula

+ 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. Replies: 3
    Last Post: 03-10-2016, 04:40 PM
  2. Replies: 9
    Last Post: 02-04-2016, 01:18 AM
  3. Adding negative number = positive in another cell.
    By agm89 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-02-2014, 03:12 AM
  4. Carrying Over Negative number to next column as a positive number
    By Redraven in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2014, 06:39 AM
  5. [SOLVED] When Cell is a negative/Positive number insert clipart next to it
    By Shannon561 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2014, 04:12 AM
  6. Replies: 4
    Last Post: 01-07-2014, 04:08 AM
  7. Move Negative Number and Change to a Positive Number
    By Alvin Hunter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2013, 08:36 PM

Tags for this Thread

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