+ Reply to Thread
Results 1 to 11 of 11

Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

  1. #1
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Ok, I'm sure my title wasn't descriptive enough. I'm trying to come up with a formula in Sheet1 that will populate the sales based on the information in Sheet2. IE: I will need the sales column on Sheet1 to go 6, 7, 8, 10, 11, 12.

    The formula I'm currently using is IF(Store1,SUMIFS(Month/Sales),IF(Store2,SUMIFS(Month/Sales),"0")

    Now this formula works fine, but the problem is that my 6 'Stores' and over 7,000 lines of 'sales' that need to be populated. Which means the formula I have above is basically 5 or 6 IF stmts nested inside eachother 7,000 times over. Not only is it ugly and hard to follow for someone reviewing, but it's making the size of my excel file dangerously close to being too large to be loaded into a program I need to use.

    Is there an easier way to achieve this without radically altering the layout of the spreadsheet?

    Sheet 1

    Store Month Sales
    Store1 Jan
    Store1 Feb
    Store1 Mar
    Store2 Jan
    Store2 Feb
    Store2 Mar

    Sheet 2

    Month Type Store1 Store2
    Jan Sales 6 10
    Jan Expenses 2 1
    Feb Sales 7 11
    Feb Expenses 3 2
    Mar Sales 8 12
    Mar Expenses 4 5


    A standard SUMIFS formula would be fine, if only there was a way to tell it to sum a different column depending on which 'store' it was without using 6 IF stmts.
    Last edited by thehotcorner; 09-13-2012 at 03:17 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Have you tried a Pivot Table?

  3. #3
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    What I'm actually trying to accomplish is a bit more involved and therefore I actually need the amounts to be populated with a formula.

    Given the simplified example, i could probably accomplish getting the 'sales' numbers using a pivot table. But I need the sales to be populated as it will link to other formulas and areas of the spreadsheet, making a pivot won't help me accomplish that.

  4. #4
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    How about..

    =SUMIF(Month_range,month,INDEX(C:I,,MATCH(Store,$C$1:$I$1,0)))

    where Column C-I have your store values
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  5. #5
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Quote Originally Posted by Ace_XL View Post
    How about..

    =SUMIF(Month_range,month,INDEX(C:I,,MATCH(Store,$C$1:$I$1,0)))

    where Column C-I have your store values
    Couldn't quite get what you were saying to work, but it did give me the idea to turn my formula 'inside out'

    So now instead of an IF stmt with 6 other IF stmts and related SUMIFS inside... I have 1 SUMIFS with 6 IF stmts nested in the SUM_RANGE. It effectively allowed me to remove 5 SUMIFS from my lengthy formula and reduce the character count by half.

    I applied the change to two columns of similar formulas I had and reduced my file size by 20%!!

    Thanks!

    EDIT: What you helped me realize was that I could use an IF stmt in the SUM_RANGE of my SUMIFS formula. Didn't know it was possible. Will come in handy in the future.
    Last edited by thehotcorner; 09-13-2012 at 04:38 PM.

  6. #6
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Couldn't quite get what you were saying to work, but it did give me the idea to turn my formula 'inside out'
    This is what I was suggesting. See highlighted columns. This should probably reduce the file size even more!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Quote Originally Posted by Ace_XL View Post
    This is what I was suggesting. See highlighted columns. This should probably reduce the file size even more!
    Awesome, worked like a charm. File size reduced by another 30%. I can now continue working without fear of the file getting too large. Didn't know I could use index/match like that.

    Now if someone wouldn't mind explaining why exactly it works, it will be easier to apply in different situations going forward. I can see what you did and replicate it obviously. But not sure why the INDEX function works to provide a dynamic range for the SUM_RANGE variable in the SUMIFS formula. If there's a simple explanation, I'd love to hear it.

  8. #8
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    The INDEX formula simply selects the entire column between ranges (column) C:H based on the match returned by the store number. Hence Col C for 1, Col D for 2, Col E for 3 and so on..

    Does this help?

  9. #9
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Is that a function of leaving the ROW variable blank? So if I were to leave the COLUMN variable blank in an instance where I would need a ROW range selected, that would work as well, I assume? Because technically I thought the INDEX formula provides specific references and using it to provide a range was different.

    Was just hoping maybe there was some underlying general excel concept that might explain it and could be applied to other formulas, etc.

  10. #10
    Registered User
    Join Date
    01-27-2008
    Posts
    17

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Also, because if I took just the INDEX portion of the formula out of the SUMIFS formula. I don't get like an error message or a sum of the range or anything. It calculates by automatically inserting a ROW variable equal to the row the formula is in.

  11. #11
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Using multiple SUMIF inside multiple IF stmts, looking for simpler solution.

    Yes the ROW variable is indeed balnk and you could adapt the same to leave a column variable blank too

+ 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