+ Reply to Thread
Results 1 to 17 of 17

Help with OFFSET formula

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    13

    Help with OFFSET formula

    Hi Everyone,

    Hoping to get some help with a formula.

    I have a calendar spreadsheet each day is in a column and different names on the rows. I need to calculate the total of the last 7 values entered in the columns for each row. Some rows start on the first column and some do not.

    Here is the formula:

    =IF((COUNT(E8:AP8)=0),"",(IF((COUNT(E8:AP8)>=7),SUM(OFFSET(E8,0,COUNT(E8:AP8)-7,1,31)),SUM(E8:AP8))))

    I know this formula might be a bit convoluted but it's mostly working. The only problem is that rows that the first value does not start on E8 (the first column) the formula is simply adding up all the values in that row with no offset.

    Sample spreadsheet attached.

    Note: I am using this formula in Google Sheets.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    Maybe this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    And, with your constraints:

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

  4. #4
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Help with OFFSET formula

    Hi,
    the easy way is to add "0" in the empty cells, so the count function will count these cells.
    Attached Files Attached Files

  5. #5
    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
    43,984

    Re: Help with OFFSET formula

    One way:

    =SUM(INDEX(8:8,N(IF(1,LARGE(INDEX(($E8:$AH8<>"")*(COLUMN($E8:$AH8)),0),{1,2,3,4,5,6,7})))))

    copied down
    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

  6. #6
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Help with OFFSET formula

    Quote Originally Posted by TMS View Post
    Maybe this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down
    Hi TMS, could you please explain the formula? when I evaluate it - it goes down to : sum($R$10:$X$10), but when I press F9 for each segment in the formula , before the ":" and after - I get the actual numbers in each of these cells:
    =SUM(7:6)
    so how does the formula work?
    Thanks.

  7. #7
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help with OFFSET formula

    Hi Guys,

    Thanks so much for the help, I was able to get this working with TMS's formula.

    I always think that I'm pretty good with Excel and then I come here and see what real pros look like.

    Truly amazing the formulas that you guys come up with off the cuff!

    Again, thanks very much for your help!

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    @Belinda:

    Each Index/Match, if evaluated independently, will return the value in the cell. However, combined with the colon ( : ), they will return an array of cells. The SUM then totals the values in the array. In Excel 2019, If you remove the SUM, the array will SPILL into the adjacent cells. So, for row 8, you get: 6 4 5 7 4 6 3

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    @ofirio: You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  10. #10
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Help with OFFSET formula

    This is marked solved, but if this is intended for Google Sheets,

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

  11. #11
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help with OFFSET formula

    Hey hrlngrv,

    Thanks for your formula!

    TMS's solution seems to be working ok for me on Google Sheets, hopefully no issues with it in the future.

  12. #12
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Help with OFFSET formula

    TMS's formula is more precise. It uses 2 MATCH calls as arguments to 2 separate INDEX calls to specify the sum range exactly. Mine uses just 1 MATCH and 1 INDEX call to find the 7th from rightmost number then sums to the rightmost extent of the range. Summing over extraneous cells which don't contain numbers does nothing to affect the results.

    That said, the 9999+E99 term in TMS's formula means the number 9999 plus the value of cell E99. I suspect he meant 9999E+99 which would be the number with 9999 followed by 99 zeros. 1E308 is a larger number value Excel can handle and requires less typing. Also, in my limited experience with Google Sheets, MATCH(HUGE_value,range) isn't as reliable as in Excel, which is why I used arrayformula(...).

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    I suspect he meant 9999E+99
    I did indeed mean that. By a happy coincidence, the version I actually used was a) large enough and b) didn't get messed up by the contents of the cell E99.

  14. #14
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Help with OFFSET formula

    Quote Originally Posted by TMS View Post
    @Belinda:

    Each Index/Match, if evaluated independently, will return the value in the cell. However, combined with the colon ( : ), they will return an array of cells......
    Wow I didnt know that....Thanks for sharing

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    OK, just to clarify:

    The formula that I offered was this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    which works ... but only if cell E99 is blank or has a numeric value. If it has an alphabetic/special character in it, it will fail, as will the formulae below it if cells E100, E101, E102, etc., have a non numeric value in them.

    That was not what I intended. What I should have typed was this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    which is better but not perfect! In fact, Excel will adjust that to:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    To quote:

    Maximum/Minimum Limitations
    All computers have a maximum and a minimum number that can be handled. Because the number of bits of memory in which the number is stored is finite, it follows that the maximum or minimum number that can be stored is also finite. For Excel, the maximum number that can be stored is 1.79769313486232E+308 and the minimum positive number that can be stored is 2.2250738585072E-308.
    See: https://docs.microsoft.com/en-us/off...ccurate-result

    What I'd normally use is this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    but, for whatever reason, I didn't look it up and/or check it out.

    You could actually put a lot more 9s after the decimal point but, to be fair, it's a bit tedious and unnecessary.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Anyway, I've probably laboured the point enough. Thanks to hrlngrv for highlighting the error before it manifested itself in real life. And, I've got to be honest, I didn't even notice the line that said it was for use in Google Sheets (or I probably wouldn't have touched it)

  16. #16
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help with OFFSET formula

    Thanks for the update!

    Google Sheets also changed it to 9.999E+102 after I typed it, everything appears to be working correctly.

    With the original formula I did have the issue with it breaking when there was not a number value in E99 but I changed E99 to the first column in that row's calendar, this cell is either blank or a number so it was working.

    Thanks again for your help everyone, much appreciated!

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,340

    Re: Help with OFFSET formula

    You're welcome

+ 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. Offset Alters Entire Range, Need To Offset A Single Cell
    By Genus Max in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-26-2020, 10:47 AM
  2. [SOLVED] Re: Is it possible to incorporate an Offset formula with a Index Match formula?
    By billrogers184 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-31-2018, 02:17 PM
  3. [SOLVED] My offset formula doesn't like referencing a cell with a formula.
    By MrOchoa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-21-2016, 01:35 PM
  4. function similar to offset to offset the offset
    By Jerseynjphillypa in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2012, 03:07 PM
  5. Reformatting - insert formula with offset, then offset to next cell
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2011, 05:41 AM
  6. Replies: 2
    Last Post: 10-08-2009, 09:51 PM
  7. Replies: 2
    Last Post: 01-03-2006, 05:42 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