+ Reply to Thread
Results 1 to 16 of 16

Simplify a complex formula

Hybrid View

Kosherboychief Simplify a complex formula 06-16-2011, 05:49 PM
brokenbiscuits Re: Simplify a complex formula 06-17-2011, 03:50 AM
Kosherboychief Re: Simplify a complex formula 06-17-2011, 09:23 AM
brokenbiscuits Re: Simplify a complex formula 06-17-2011, 09:26 AM
Kosherboychief Re: Simplify a complex formula 06-17-2011, 09:44 AM
daddylonglegs Re: Simplify a complex formula 06-17-2011, 09:50 AM
martindwilson Re: Simplify a complex formula 06-17-2011, 09:59 AM
Kosherboychief Re: Simplify a complex formula 06-17-2011, 10:33 AM
martindwilson Re: Simplify a complex formula 06-17-2011, 11:21 AM
Kosherboychief Re: Simplify a complex formula 06-17-2011, 11:40 AM
martindwilson Re: Simplify a complex formula 06-17-2011, 11:47 AM
Kosherboychief Re: Simplify a complex formula 06-17-2011, 11:55 AM
martindwilson Re: Simplify a complex... 06-17-2011, 07:26 PM
Kosherboychief Re: Simplify a complex... 06-18-2011, 03:40 AM
daddylonglegs Re: Simplify a complex... 06-18-2011, 08:22 AM
Kosherboychief Re: Simplify a complex formula 06-20-2011, 09:34 AM
  1. #1
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Simplify a complex formula

    Hello!

    I need help shortening this formula:
    =SUM(SUMIF(INDIRECT({"'January","'February","'March","'April","'May","'June","'July","'August","'September","'October","'November","'December"}&"'!B:B"),$B7,INDIRECT({"'January","'February","'March","'April","'May","'June","'July","'August","'September","'October","'November","'December"}&"'!"&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN()))))
    There are no gaps in between the sheets, and for the life of me I can't figure this out! The formula works in this form, it just....seems tacky? IDK a short formula is just so much smarter looking. No matter how hard I think, my brain is just coming back 404 whenever I try to figure out how to shorten it

    Please help
    Last edited by Kosherboychief; 06-20-2011 at 09:35 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Simplify a complex formula

    I haven't actually tested this, but I'd maybe expect the formula to be something along the lines of:

    =SUMIF(January:December!B:B, B7,indirect("January:December!"&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN())))

    ?

  3. #3
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    Quote Originally Posted by brokenbiscuits View Post
    I haven't actually tested this, but I'd maybe expect the formula to be something along the lines of:

    =SUMIF(January:December!B:B, B7,indirect("January:December!"&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN())))

    ?
    Sorry, no, it just comes back as #value!

    Would it help if I attached a sample file?

  4. #4
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Simplify a complex formula

    It can't hurt!

    Give it a go, and we'll see.

  5. #5
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    The numbers are of course random
    Attached Files Attached Files

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,717

    Re: Simplify a complex formula

    If you want to shorten by getting rid of the long "array constant" with the sheet names then one way is to list the sheet names somewhere on your sheet, e.g. in Z2:Z13, and then name that range Sheetlist and use this formula

    =SUMPRODUCT(SUMIF(INDIRECT("'"&Sheetlist&"'!B:B"),$B7,INDIRECT("'"&Sheetlist&"'!"& ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN()))))

    alternatively you could use a formula to generate the month names, e.g.

    =SUM(SUMIF(INDIRECT(TEXT({1,2,3,4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&"B:B"),$B7,INDIRECT(TEXT({1,2,3,4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN()))))

    ....and using the first version with a simplification of the ADDRESS part....

    =SUMPRODUCT(SUMIF(INDIRECT("'"&Sheetlist&"'!B:B"),$B7,INDIRECT("'"&Sheetlist&"'!"& CELL("address",INDEX(1:20000,0,COLUMN())))))
    Last edited by daddylonglegs; 06-17-2011 at 09:54 AM.
    Audere est facere

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Simplify a complex formula

    create a named range of the months call it say "monthsheets"
    then in c4 you can use
    =SUMPRODUCT(SUMIF(INDIRECT("'"&monthsheets&"'!$B$4:$b$16"),B4,INDIRECT("'"&monthsheets&"'!$c$4:$c$16")))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  8. #8
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    @daddylonglegs, your

    =SUM(SUMIF(INDIRECT(TEXT({1,2,3,4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&"B:B"),$B7,INDIRECT(TEXT({1,2,3, 4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN()))))

    solution works the best so far (If I hide the cell that has the named range, my very OCD co-workers will notice, TRUST ME, and unhide it, which bugs me) however, I am having difficulty using the location parts of the formula in another formula from another book that I want to use to average the months which is
    =IFERROR(=SUM(SUMIF(INDIRECT(TEXT({1,2,3,4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&"B:B"),$B7,INDIRECT(TEXT({1,2,3, 4,5,6,7,8,9,10,11,12}*29,"'mmmm'!")&ADDRESS(1,COLUMN())&":"&ADDRESS(20000,COLUMN()))))/SUMPRODUCT(COUNTIFS(INDIRECT("'Week "&{1,2,3,4,5}&"'!A1:A1000"),$A6,INDIRECT("'Week "&{1,2,3,4,5}&"'!"&ADDRESS(1,COLUMN())&":"&ADDRESS(1000,COLUMN())),">0")),"")

    Any tips?

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Simplify a complex formula

    fyi you dont have to put months in a range of cells to create a named range you can just create a named range of
    ={"january";"february";"march";"april";"may";"june";"july";"august";"september";"october";"november";"december"}

  10. #10
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    Quote Originally Posted by martindwilson View Post
    fyi you dont have to put months in a range of cells to create a named range you can just create a named range of
    This actually causes it to return an incorrect sum

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Simplify a complex formula

    no it doesnt
    it gives same values you have see attached named range is called "testing"
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    My bad, I must have done my test incorrectly, your formula works well. How do you think I could use it to average?

  13. #13
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Simplify a complex formula [NOT SOLVED :( ]

    dont you just divide total by 12?

  14. #14
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula [NOT SOLVED :( ]

    Quote Originally Posted by martindwilson View Post
    dont you just divide total by 12?
    If all the values were filled in for all the months, then yes, if they are not, it will divide by too many.

    Ex. Average of 10,10,10,10,10 is 10, but if, lets say we are using our formulas from above then the 10+10+10+10+10, instead of being divided by 5 (because there are 5 numbers being averaged) would be divided by, say, 8 is 6.25
    Average means sum/however many numbers you are summing, and for this problem, the formula needs to be able to detect and ignore zeros and blanks

  15. #15
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,717

    Re: Simplify a complex formula [NOT SOLVED :( ]

    You should be able to do it as you tried, e.g. using Martin's suggested formula for the sum then the average would be

    =SUMPRODUCT(SUMIF(INDIRECT("'"&monthsheets&"'!B4:B16"),B4,INDIRECT("'"&monthsheets&"'!C4:C16")))/SUMPRODUCT(COUNTIFS(INDIRECT("'"&monthsheets&"'!B4:B16"),B4,INDIRECT("'"&monthsheets&"'!C4:C16"),">0"))

  16. #16
    Registered User
    Join Date
    01-31-2011
    Location
    Texas, USA
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Simplify a complex formula

    Thanks daddylonglegs and martindwilson, I learned a bunch and the problem was solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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