+ Reply to Thread
Results 1 to 13 of 13

Subtract 1 from last 5 records

  1. #1
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Subtract 1 from last 5 records

    After trying countless of hours I almost don’t want to ask for help cause I want solve it myself but it's time to toss in the towel and turn to someone that can guide me.

    If value in Column A is -1 I want the last 5 records (rows) in Column B to also be -1. If the cell in Column B already has value -1 I want it to decrease to -2. New values to columns will be continuously added.


    A B
    0 0
    0 -1
    0 -1
    0 -1
    0 -2
    -1 -2
    0 -1
    0 -1
    -1 -1
    0 0
    0 0
    etc. etc.

    Data is in a table, I am not using VBA and version is Microsoft 365.

    Kindly let me know if any additional information is needed.

    Many thanks!

  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. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,448

    Re: Subtract 1 from last 5 records

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    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
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Thanks for the welcome!

    Please see attached manual example.
    Attached Files Attached Files

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Subtract 1 from last 5 records

    Pls explain:
    A6=0, B6=-2 (should be -1?)
    A10=-1, B10=-1 (should be -2?)
    Quang PT

  5. #5
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Thanks for the quick response.

    A6=0, B6=-2
    Because B6 is within previous 5 records from A10 and A7 B6=-2. (B5=-1 because it is 6 records from A10 hence it is excluded)

    A10=-1, B10=-1
    Because next 5 records from A10 do not contain -1

  6. #6
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Perhaps it’s unclear. I’d like a function for:

    If A8=-1 then B8=B8-1, B7=B7-1, B6=B6-1, B5=B5-1, B4=B4-1

    Your ideas on how to do this is welcomed. Thanks.

  7. #7
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Subtract 1 from last 5 records

    Maybe try at B2
    =SUM(A2:A6)
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Thank you!

    Haha! I've been blinded by my attempts of using endless IF statements with Count etc. It's so simple when I see it!

    However, the total/final formula I am looking for has more to it but Ill hack away before potentially seeking guidance again.

    Again, Thanks!

  9. #9
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Im back…

    Although the spreadsheet works as it is it I would like to make it “leaner” so that there are only 3 columns instead of 4.

    How would I go about setting up the SUM() function so that it also calculates A-B?
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-02-2020
    Location
    Paris, France
    MS-Off Ver
    Professional Plus 2013
    Posts
    41

    Re: Subtract 1 from last 5 records

    Hi kermittaipan,

    You changed something in your data. The value isn't always lower in column A compare to column B, so a simple substraction would provide positive results instead of negative ones.
    After using a lot of ABS() here is the end result attached for your enjoyment.

    Cheers.
    Attached Files Attached Files

  11. #11
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Subtract 1 from last 5 records

    Please try

    =-SUMPRODUCT(ABS(G3:G7-H3:H7))
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Exl-Noob and Bo_Ry,

    thank you for the solutions. They both work perfectly!

    I will continue to fiddle around with this to try to reach my final formula.

    Thanks and I might be back with a questions.

  13. #13
    Registered User
    Join Date
    10-26-2020
    Location
    Jakarta
    MS-Off Ver
    Microsoft 365
    Posts
    11

    Re: Subtract 1 from last 5 records

    Finally managed to get final formula done. I realize it is different from what I originally asked but I just wanted to a hint in order to learn by doing.

    I came up with:

    =SUM(IFS((A3:A22-B3:B22)<=-10;-2;(A3:A22-B3:B22)<=-7;-1;(A3:A22-B3:B22)>-7;0))

    If it could be improved/more efficient let me know.

    Thank you for the 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. Subtract until 0 then move to next cell to subtract until 0
    By manateee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-15-2020, 03:32 AM
  2. Replies: 5
    Last Post: 04-13-2020, 07:41 AM
  3. Is it possible to subtract records using criteria?
    By icyrius in forum Access Tables & Databases
    Replies: 4
    Last Post: 12-16-2019, 11:35 AM
  4. Find the initial parent record based on the records in the last child records
    By Journeyman3000 in forum Access Tables & Databases
    Replies: 0
    Last Post: 03-30-2017, 08:46 PM
  5. [SOLVED] how to subtract a set value from a cell when a another cell records a value of 1
    By dazzinator in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-10-2013, 06:15 PM
  6. If Sat subtract one day, if Sunday subtract tow days
    By Wskip49 in forum Excel General
    Replies: 3
    Last Post: 06-30-2012, 03:35 PM
  7. How can I subtract from Duplicate Records?
    By mn_excel_91 in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 09-23-2009, 02:37 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