+ Reply to Thread
Results 1 to 11 of 11

Using Sum(IF(AND(....))) Not working and can't figure out why

  1. #1
    Registered User
    Join Date
    05-02-2014
    Location
    Paris, France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Using Sum(IF(AND(....))) Not working and can't figure out why

    Sorta complicated so will do my best to explain...
    Here is what my data looks like (did my best to format it but came out a little weird, hope it's still readable):

    Please Login or Register  to view this content.
    So I'm trying to write a formula where if in column B, the number after the / is greater than the number before, and the name in column A is Alex, it adds the values in column C. I wrote a formula that says TRUE when I place it in row 4, but my formula is still not working.

    Here is the formula I am using:
    =SUM(IF(AND(IFERROR(RIGHT(B1:B6,LEN(B1:B6)-SEARCH("/",B1:B6))/LEFT(B1:B6,SEARCH("/",B1:B6)-1),0)>=1,A1:A6="ALEX"),C1:C6))

    I press ctrl-shift-enter and I come back with 0.

    When I put in the formula:
    =IF(AND(IFERROR(RIGHT(B4,LEN(B4)-SEARCH("/",B4))/LEFT(B4,SEARCH("/",B4)-1),0)>=1,A4="ALEX"),C4)
    I get 20

    I'm not sure what I'm doing wrong here

    Thank you.

    Just wanted to add: I got this formula to work using nested if statements, but would rather use the AND function if possible since there are many more criteria, I just included these to simplify it.
    Last edited by DeeRok; 05-02-2014 at 02:00 PM.

  2. #2
    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
    44,055

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    This doesn't look too complicated. BUT it is not clear what result you EXPECT to see in your examples. Please post a column D, showing what you EXPECT as the answer.

  3. #3
    Registered User
    Join Date
    05-02-2014
    Location
    Paris, France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    I don't want a column D. I just want one cell with a formula that would sum all the values of column C where the criteria are met... I can post a sample excel document if it's allowed (new to this forum, not sure the rules) and would be helpful.

    Basically The only value that should be added is C4

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    Try this......

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  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
    44,055

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    Yes but added to WHAT? In the case of row 4, 20 would be added to??? 500 or 3000?

  6. #6
    Registered User
    Join Date
    05-02-2014
    Location
    Paris, France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    Quote Originally Posted by sktneer View Post
    Try this......

    Please Login or Register  to view this content.
    I made code that works with nested if statements, but would prefer to use the AND function if possible but the actual spreadsheet has many more criteria

  7. #7
    Registered User
    Join Date
    05-02-2014
    Location
    Paris, France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    Quote Originally Posted by Glenn Kennedy View Post
    Yes but added to WHAT? In the case of row 4, 20 would be added to??? 500 or 3000?
    Sorry if I wasn't clear, I just mean the values would be summed. Basically the formula sktneer gave, but don't want to use nested if's if possible.

    There will be another cell, F50, that will contain a sum of all the cells of column C where the criteria is met.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    The problem with the AND inside the IF statement is, if you get any false value inside the array returned by the AND statement, the AND will evaluated to be False and hence you will not get the correct value. Instead use nested IF statement.

  9. #9
    Registered User
    Join Date
    05-02-2014
    Location
    Paris, France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    Got it sktneer, thanks a lot. Is there any better way to do it with 10+ criteria without it looking like a mess?

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    You have no other option but to add the multiple criteria using the nested IF statements.

    If that takes care of you question, please mark your thread as solved by selecting the Thread Tools (just above your first post) --> Mark thread as solved.
    Moreover you may also click on * (star) to Add Reputation to those who have put their time and efforts to help you in this forum. This is another way to say thanks to them.

  11. #11
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Using Sum(IF(AND(....))) Not working and can't figure out why

    If you need add more criteria use this:

    =SUM((RIGHT(B1:B6,LEN(B1:B6)-SEARCH("/",B1:B6,1))/LEFT(B1:B6,SEARCH("/",B1:B6,1)-1)>=1)*(A1:A6=A9)*(C1:C6))

    you can add more criteria with add bracket "*(ranges=criteria1)*(ranges=criteria2) and the last bracket is number you'll add up

+ 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. I screwed up a formula which was working fine and cannot figure it out!!!
    By boomtown25 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-21-2014, 10:52 AM
  2. Macro Not working, cant figure out why!
    By tezzaaa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2014, 05:39 AM
  3. Please help, I can't figure out why countifs( isn't working
    By Blackhawks in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-10-2014, 09:56 PM
  4. Replies: 4
    Last Post: 02-03-2014, 08:05 AM
  5. IF THEN not working, can't figure out error
    By tspevak in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-25-2013, 04:55 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