+ Reply to Thread
Results 1 to 15 of 15

Array formula to return all steps of cumulative / running total

  1. #1
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Array formula to return all steps of cumulative / running total

    Hi all,

    I'm scratching my head around an array formula that I'm trying to build. It has to be an array since I need to use it as an input for a function.

    Bascially what I'm looking for is the equivalent of each step of a cumulative / running total but in array form. It's easiest explained with an example so an image and workbook is attached.

    arraycml.PNG

    What I am aiming for is col D "Array Cml" to have an identical output to col C "Cml Sales" using only col B "Sales".

    Can anyone point me in the right direction?

    Thanks
    Attached Files Attached Files
    Design everything to be as simple as possible, but no simpler.

  2. #2
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,935

    Re: Array formula to return all steps of cumulative / running total

    What is your expected result ?
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Array formula to return all steps of cumulative / running total

    Column D

    in D2

    =SUM($B$2:B2)

    copied down


    ???

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Guys, I included all of this information in the original post

    1. Expected result is for an array formula in col D to output the values given by individual formulas in col C

    2. Not an array formula, that is the group of non-array formulas in col C

  5. #5
    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
    80,780

    Re: Array formula to return all steps of cumulative / running total

    There is little point in rolling your eyes at people who are trying to help you - it's not terribly courteous, either.

    A better approach might be to show where you want to use the array: what is the formula you are trying to build? There may be a more appropriate way of doing this.
    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.

  6. #6
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Array formula to return all steps of cumulative / running total

    =subtotal(9,offset(b2:b13,,,row(b2:b13)-1,))
    Attached Files Attached Files
    Last edited by tim201110; 03-28-2018 at 05:50 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Quote Originally Posted by AliGW View Post
    There is little point in rolling your eyes at people who are trying to help you - it's not terribly courteous, either.
    It was a happy and jolly eye-roll with a smile on my face ("ohhh you guysssss!")--I cannot help but laugh at these things and emoticons are limited


    I think you are right that more context is probably required.
    So my final goal is to apply linear regression to monthly sales, however I would like to apply the regression to the cumulative totals and adjust for zero-intercept so that I get a model for forecasting sales in future months (one that's a 'better' fit than just taking the mean across all months, especially when we start drilling down to individual sites).

    There are three caveats which complicate this:
    1. My sales data is not in one continuous array so will need to filter it out in-situ using an array formula and/or SUMPRODUCT()
    2. My sales data includes 0s for future months for which I would need the cumulative total to 'stop'
    3. Contrary to my usual ideology, I do not wish to use helper columns since I have a requirement for no hidden columns in this report

    I have attached a workbook showing my final goal and how to get there using manual intervention and manual columns. The challenge is to replicate this into one formula regardless of how complicated it is.
    Attached Files Attached Files

  8. #8
    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
    80,780

    Re: Array formula to return all steps of cumulative / running total

    We like a challenge!

    Thanks for the extra information - I am sure it will prove useful.

  9. #9
    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
    80,780

    Re: Array formula to return all steps of cumulative / running total

    Do you have Office 365?

  10. #10
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Unfortunately not, just Office 2016, so I cannot use 365 exclusive functions such as SWITCH() etc.

  11. #11
    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
    80,780

    Re: Array formula to return all steps of cumulative / running total

    That's a shame, because I had come up with this:

    =SUBSTITUTE(SUBSTITUTE(TEXTJOIN(",",TRUE,IF(B7:J7="TOT",B8:J8)),"FALSE",""),",,","")

    ... array entered.

    It returns the values needed for the first TREND formula. It was just a start - maybe could be replicated with CONCATENATE?

    I'm beginning to feel that you will probably need a UDF somewhere along the way here.

  12. #12
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Trying to avoid using a UDF since I purge all the VBA from the file when I generate the 'static' version for circulation, but the directors who receive it like to see all the formulas in there so that they can remember how things are calculated. This one will definitely require a comment!!

    I spent some more time on this yesterday afternoon. I have used Tim's clever little SUBTOTAL(OFFSET()) resizing formula to generate the cumulative totals inside the final formula (+rep added). However I can't seem to use an array input for the OFFSET() section of Tim's formula, meaning I have to pull out the "TOT" values in a separate helper row.
    This is a "so close yet so far" situation. Is using SUBTOTAL(OFFSET()) viable and just requires a bit of work to sum only the "TOT" values, or is this the closest this method can get? Are there any other ways of getting each step of cumulative totals into an array?

    So close...

    Edit: I have given up on the TREND() formula since it counts all the zeros (i.e. where I am deleting non-relevant data by multipling by zero) as datapoints. By calculating it manually I can sum-out the zeros I have generated. Generating Sigma(xx) is easy, it's generating the Sigma(xycml) that's tricky because of the ycml part.
    Attached Files Attached Files
    Last edited by Stormin'; 03-29-2018 at 04:42 AM.

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Array formula to return all steps of cumulative / running total

    If you want cumulative "TOT" values ..

    in C56

    =IF(OFFSET($A$8,,COLUMNS($B:B)*3,,1)>0,SUMPRODUCT((OFFSET($B$8,,,,COLUMNS($B:B)*3))*(OFFSET($B$8,-1,,,COLUMNS($B:B)*3)="TOT")),0)

    Copy across

    In C57 (for corresponding years)

    =IF(OFFSET($A$8,,COLUMNS($B:B)*3,,1)>0,INDEX((OFFSET($B$8,-2,,,COLUMNS($B:B)*3)),,COLUMNS($B:B)*3),0)

  14. #14
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Hi John,

    Thanks for spending the time creating those formulas. However the type of formula I'm looking for is a static array, because we cannot 'copy accross' inside a single-cell formula. I'm looking to eliminate the helper row and have the entire calculation in a single cell.

    If you use 'Evaluate Formula' in cell D59 you can see this happening by creating arrays inside the formula. However it doesn't work because either the SUBTOTAL() or OFFSET() function is not working properly when faced with a direct array rather than a cell reference. I have a feeling it's the OFFSET() function which is built to work off of cell ranges, not arrays of values...

  15. #15
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Array formula to return all steps of cumulative / running total

    Ok, so I have solved my specific problem. Not by getting the OFFSET() function to accept arrays inside the formula, but rather by looking at the maths behind specifically what I am currently getting vs what I actually want.

    Currently I am getting a cumulative sum of B1, B2, and TOT all added together, and multipling by the month number.
    Quickly renaming B1 = A, B2 = B, TOT = y gives:

    CodeCogsEqn.png

    I was trying to extract just y (TOT) only, but because by definition y = A + B (TOT = B1 + B2) you'll notice that we get:

    CodeCogsEqn(1).png

    So now it is easy to see that we just need to divide by 2 to get the equation required, in all cases, with any amount of parts for y:

    CodeCogsEqn(2).png


    My updated formula gives me the target of 3695:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then just dividing by the sum of the x2's gives me my final regression coefficient of 263.929 in a single cell!

    Perhaps if I had used more rounded example numbers I would have noticed earlier lol.

    Thanks everyone for helping me get to this solution!
    Sorry that I couldn't figure out a more general solution to the formula problem, for anyone looking at this in the future... but good luck

+ 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 return the last figure in a running total
    By OAKLEY in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-29-2013, 01:47 PM
  2. Cumulative (Running) Total.
    By dillkeva in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-14-2013, 06:56 AM
  3. Replies: 4
    Last Post: 09-05-2012, 05:25 AM
  4. Help with Formula to return running YTD total based on a date range
    By RubiksCuber in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 06:09 PM
  5. help running/cumulative total
    By rjc_29 in forum Excel General
    Replies: 2
    Last Post: 06-04-2007, 09:27 AM
  6. Formula Needed to Compare Dates and return a running total
    By Cmonroe in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-08-2006, 03:55 PM
  7. Subtotal and running/cumulative total!
    By rahul25 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2005, 04:10 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