+ Reply to Thread
Results 1 to 6 of 6

Need formula(s) for Moving Totals to automatically update within that or another formula

  1. #1
    Registered User
    Join Date
    03-23-2012
    Location
    Malibu, California
    MS-Off Ver
    Excel 2007
    Posts
    39

    Need formula(s) for Moving Totals to automatically update within that or another formula

    I'm looking to track cell elements to do moving totals that will update automatically by adding in each new addition while dropping off the oldest element. These cell elements are text, not values, and they are in rows / row pairs. New elements are not uniformly added throughout the worksheet, meaning the timing can vary. The formula needs to update as soon as each element is added. There are column headings that are numbered (as an example: 1 through 150) that I thought perhaps could be used somehow as a counter or a way to identify the farthest column in an appropriate array/range and then count back to get the beginning of the array/range? I tried working with a variety of functions (MATCH, INDEX, OFFSET, etc.), but I am not familiar enough with them to know how to make them work or even if they would be workable or yield the appropriate results. I don't want to have to manually re-define an array over and over, for that defeats the purpose of automating this.

    Here is an example of the basic layout:


    1 2 3 4 5 6 7 8 9 10 11 12 15 16 17 18 ... ... 150 Total n/y Total both

    n n n n n n n n n 9

    y y y y y y y 7
    16

    The most recent (largest and farthest to the right) row heading number that is populated in either of the rows (n or y) below it is what I am interested in finding to use in a formula that would add, say the last 6 entries of n and the last 6 entries of y, separately going back from that point and inclusive. Thus the moving totals (Columns 1-6, 2-7, 3-8, 4-9, etc.). I thought to use the "Total both" column and find that number in the heading row to provide a cell reference and hence a column, then count backward from that column. So far that hasn't worked for me.

    This just shouldn't be that difficult, but it is something I have never run across before. Any help with this would be GREATLY appreciated!!!

  2. #2
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Need formula(s) for Moving Totals to automatically update within that or another formu

    This will return a result from row 1 based on finding the last non-blank cell in row 2.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Change the ranges to match the columns you have data in.

    Hope that helps.
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  3. #3
    Registered User
    Join Date
    03-23-2012
    Location
    Malibu, California
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Need formula(s) for Moving Totals to automatically update within that or another formu

    This is great and it gets me to the last entry so I know how many entries there are in a row. I was not familiar with this LOOKUP syntax, but it works for this first step.

    I believe there are actually 4 steps involved in what I need to do:
    1) Identify the last entry for each row (Which you helped me do - thank you very much!)
    2) Identify the column reference for that last entry
    3) Count backward from that point by say 6, to get the column for beginning of the range
    4) Count the number of n's or y's in that range.

    I'm not sure how to proceed after step 1. I need to come up with a range using that end point and working back that will automatically adjust with each new addition. Can I somehow take the result from step 1 and subtract 5 to get the range (6 periods), then perhaps use the ADDRESS function to come up with column references for the beginning and end of the range? (Once I have a range I could probably just use COUNTIF to count the n's and y's.)

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Need formula(s) for Moving Totals to automatically update within that or another formu

    Note to self - read the full question so I can answer all of it (I blame being on night shift having been awake for over 24hrs!)
    Anyway, back to your question: I'll go through it in stages. You're on exactly the right lines by considering using the Address function.

    1. The formula I gave above will find the last non-blank entry in the range A2:Z2 (as I said above) then return the result from A1:Z1 (that bit of the formula is the 'result vector').

    2. To get the column reference, we can change the result vector to give the column:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I've made the column refs absolute but left the row refs relative, for dragging down. What this will give is the column number - for example '25' (not the 25th column in the range, but the 25th column in the worksheet). However, for building a range, we need the column letter.
    This is a common question in Excel - how to convert the numerical result of 'Column' to the column letter. Luckily, there's a simple solution to it, which is to put the result into the 'Address' function, just as you had already thought of . Putting our formula from above into the 'column ref' part gives us:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    If the previous result was '25' this will give us '$Y$2' (since column Y is column 25). So that's the cell address of the last non-blank cell in the range A2:Z2.

    3. To find the cell address six back from there, just subtract 5 from that number - as you said:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This will give you $T$2.

    4. To put those two results into another formula as a range, you need to combine them using the Indirect function. Where you would normally put the range (for example $T$2:$Y$2), you would use this instead:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Your two choices are CountIf (to count 'n' or 'y') and CountA (to count non-blanks):
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Personally, I'd probably use CountA, as you can then drag it down without having to change the 'n' to a 'y' - but if you don't have too many rows to do then you might prefer to be explicit.


    The attached file shows all of this working. Hope that's what you need.

  5. #5
    Registered User
    Join Date
    03-23-2012
    Location
    Malibu, California
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Need formula(s) for Moving Totals to automatically update within that or another formu

    Hello Aardigspook! I'm sorry it took me so long to get back to you. Your formula is brilliant and it worked and did what I needed. Fabulous job! I can't thank you enough! I did want to comment that while the cell references copied down fine since they weren't strung, I did have to change the Lookup rows (2,1) as I went. I was also confused why the formula only worked if it was on the same row as that data. It seems that the formula should have worked where ever it was, but it didn't. I ended up using the same row, but I am curious why this would be.

    Again, brilliant job!!! Thank you so much!!! You made my day and saved me tons of time!!!

  6. #6
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: Need formula(s) for Moving Totals to automatically update within that or another formu

    You're welcome and thanks for the rep.

    The reason the formula only works on the same row as the data is the inclusion of ROW() in the Address() parts of the formula. That will always return the row which the formula is on. For example, if your formula is on row 4, ROW() will return '4'. If you want it to refer to row 2 instead, then you need to include a cell ref: ROW(A2) for example.

    So, to put the formula which refers to row 2 on another row, you can change the CountIf/CountA formulae to:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Hope that makes sense.

    Edit: since I'm explaining one part of the formula, I might as well explain the Lookup part too.
    • Lookup syntax is Lookup ( a value , in an array , give result from another array-optional ). The important thing to remember about Lookup is that it looks through the array in ascending order and returns the nearest match working backwards.
    • So, in the formulae above, $A2:$Z2<>"" will give an array of True/False statements, like this: {True, False, True, True, False}.
    • Excel treats True as 1 and False as 0, so 1/True gives 1, and 1/False gives a #Div/0 error. So the above array becomes: {1,#DIV/0!,1,1,#DIV/0!}
    • Lookup then looks through this for the value it's been told to find, in this case 2. It doesn't find it, so returns the position in the array which is closest, -working backwards-. That, in this case, is the fourth value.
    • If there's a 'result vector' specified, the Lookup will then return the equivalent value from that vector. So if the result vector for the above example were {11,22,33,44,55} the Lookup would return the fourth value, 44.
    I hope that helps understand what the 'Lookup' is doing.
    Last edited by Aardigspook; 07-15-2017 at 01:30 PM. Reason: Add further explanation

+ 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. [SOLVED] Formula to update balance totals?
    By maurerjl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-11-2015, 01:22 PM
  2. Formula does not update automatically
    By Franziska in forum Excel General
    Replies: 4
    Last Post: 06-28-2010, 08:50 AM
  3. Formula needed - automatically calculate session time totals for each user
    By optimusprym8 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-22-2006, 09:01 AM
  4. Formula needed - automatically calculate session time totals for each user
    By optimusprym8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-22-2006, 06:42 AM
  5. [SOLVED] My formula doesn't update totals when I change numbers.
    By Ozymandias in forum Excel General
    Replies: 3
    Last Post: 10-23-2005, 06:05 PM
  6. [SOLVED] Can I set up the formula to update automatically?
    By pugsly8422 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-23-2005, 01:06 PM
  7. [SOLVED] moving formula resupts to another sheet automatically
    By jv in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-27-2005, 10:06 AM

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