+ Reply to Thread
Results 1 to 33 of 33

SUMIF formula needs criteria, or help me with another formula please - with example.

  1. #1
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    SUMIF formula needs criteria, or help me with another formula please - with example.

    Hi,

    I'm attaching a little example of an excel sheet. The actual one is confidential and huge (over 40 columns 650 rows, and 20+ sheets) it also has many macros and apart from column A and B all columns are full with calculations. It has been developed over years through many people.. some knew what they do some didn't, and so far no one made an effort to clear it up.. to add new rows we have a macro, but we can not add new columns, as some of the macros and calculations break. I also think it is not necessary for this calculation that I need to add in, but it could be done with a pivot table in my example, in the excel sheet I have it is not possible.

    So: First column is strawberries or blueberries second column is random weight values. The third column decides if they are counted or not (0 or 1) the fourth column is =B*C and D2 is a SUM of D column.

    In the C column for the strawberries there is a number, either 0 or 1 but for the blueberries it refers to other cells which are also 0s or 1s but this allows for the blueberries to be counted in cell D2 if we want them to be counted or to not be counted when we don't want them counted. (I need to keep it like that!)

    Now the complication is: for the blueberries in C column we refer to 2 other cells, one of them is "Blueberries qtty" the other one is "Additional blueberries". I would need to SUM the Blueberries but not the ones that are additional.
    NO MATTER IF THE CELL VALUE IN C IS 0 OR 1 IT ALWAYS NEEDS TO BE THE SAME NUMBER (-4 in the example). There are Blueberries with Negative value in column B, so <0 doesn't work because the negative ones will be counted but they are additional so they shouldn't be. (Row 7 in the example)

    Formula would be something like: =SUMIF(A5:A13,"Blueberry",B5:B13) but this doesn't take into consideration that I don't want the "Additional blueberries" counted.

    So in my head it should look something like: =SUMIFS(B5:B13,A5:A13,"Blueberry",C5:C13, ???PLEASE HELP???) so how do I express in excel language: C column, whichever row, cell contains =$L$9 cause "=$L$9" doesn't seem to work.. and so far nothing else I tried.

    If there is another formula that would do and fit the my excel sheet as I explained above, then I'm open for it just please explain what your formula does.. I'm not really good in excel and I would like to learn.
    Attached Files Attached Files
    Last edited by LIL2606; 09-07-2017 at 08:56 AM.

  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,054

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    =SUMIFS($B$5:$B$13,$A$5:$A$13,"Blueberry",$C$5:$C$13,1)

    or

    =SUMIF($A$5:$A$13,"Blueberry",$D$5:$D$13)
    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

  3. #3
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    like this one?
    =SUMIFS($B$5:$B$13,$B$5:$B$13,"<"&$L$9,$C$5:$C$13,$L$6,$A$5:$A$13,"Blueberry")

    too late refresh

    something different
    =SUMPRODUCT(($A$5:$A$13="Blueberry")*($B$5:$B$13<$L$9)*($C$5:$C$13=$L$6)*$B$5:$B$13)
    Last edited by sandy666; 09-07-2017 at 07:37 AM.

  4. #4
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @ Glenn Kenedy

    "Formula would be something like: =SUMIF(A5:A13,"Blueberry",B5:B13) but this doesn't take into consideration that I don't want the "Additional blueberries" counted.

    So in my head it should look something like: =SUMIFS(B5:B13,A5:A13,"Blueberry",C5:C13, ???PLEASE HELP???) so how do I express in excel language: C column, whichever row, cell contains =$L$9 cause "=$L$9" doesn't seem to work.. "

    I need to add them regardless the value in C. I just tried to explain that the difference between some "Blueberry" and other "Blueberry" is that in column C they take their value from a different cell.

  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,054

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Did you try the two formulae? they BOTH give -4, which was (I believe...) your expected answer.

  6. #6
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @Sandy666
    Thank you but the first SUMIF formula is the one that I have in the example currently. It is not good because I have both positive and negative numbers among the additional Blueberries, so it will add the negative Additional blueberries..

    The SUMPRODUCT doesn't work either if the value in C changes from 0 to 1.
    Last edited by LIL2606; 09-07-2017 at 08:32 AM.

  7. #7
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @ Glenn Kenedy

    If you change the value in L9 to a 1 instead of a 0, none of them gives -4. I need this to be -4 no matter if there is a 0 or a 1 standing beside them.

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    =SUMIFS($B$5:$B$13,$B$5:$B$13,"<"&$L$9,$C$5:$C$13,$L$6,$A$5:$A$13,"Blueberry")
    SUMPRODUCT(($A$5:$A$13="Blueberry")*($B$5:$B$13<$L$9)*($C$5:$C$13=$L$6)*$B$5:$B$13)

    result for both : -4 (with conditions in the workbook: qtty = 1, additional = 0) if you change conditions result will change also

    =SUMPRODUCT({0;0;0;0;0;1;1;0;0}*{1;2;-3;-3;4;-1.5;-2.5;5;10})
    result of conditions {0;0;0;0;0;1;1;0;0}
    range of your data {1;2;-3;-3;4;-1.5;-2.5;5;10}
    0 eliminate unnecessary values, so result will be: SUM of these two -1.5;-2.5
    Last edited by sandy666; 09-07-2017 at 08:42 AM.

  9. #9
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @Sandy666
    The same goes as for Glenn Kenedy
    I need that -4 to be constantly -4 but if I change the value in L9 the sumproduct will give -7 the sumif will still be okay because I have big numbers but it would not be the right value if I had an Additional blueberry with the value of 0.5 which may happen in my original excel sheet I don't know for sure, as I didn't go through all the 650+ values in the 20 sheets.

  10. #10
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    I fixed the original description of the problem to include the problem of being regardless of the value of C. Sorry for the misunderstandings before.

  11. #11
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    If you want independent conditions
    =SUMIFS($B$5:$B$13,$B$5:$B$13,"<0",$C$5:$C$13,1,$A$5:$A$13,"Blueberry")
    =SUMPRODUCT(($A$5:$A$13="Blueberry")*($B$5:$B$13<0)*($C$5:$C$13=1)*$B$5:$B$13)
    or I don't understand logic

  12. #12
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    The values you want to sum for Blueberry in column B are always the same ? [ -2.5, -1.5 ]
    you can try
    =SUMPRODUCT($B$5:$B$13,($A$5:$A$13="Blueberry")*(LEN($B$5:$B$13)=4))
    but to me this is non-sense

  13. #13
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy666

    So the logic is:
    Depending on what we want to see in D2 we turn change the values in column C. We have 2 types of Blueberries 1 type is the ones we will almost always want to count in D2 and their cell in C refers to L6 (so if L6 is 1 they are counted in D2 if L6 is 0 they aren't counted in D2) and there are the Additional Blueberries which's cell refers to L9 (if L9 is 1 we count them in D2 if 0 we don't) So in D2 we can see the sum of: only the strawberries, strawberries and blueberries qtty, strawberries and additional blueberries, or strawberries and both.
    This needs to stay like that.

    I need a separate calculation that will sum the "blueberries gtty" for me and only those, no matter if they are counted in D2 or not. (so no matter if the cell value beside them is 0 or 1)

    So I would need something like a SUMIF criteria (according to the example) that looks into column C and sees, C13 is =$L$9, so I don't count that one..

  14. #14
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    like this one?
    =SUMPRODUCT(($A$5:$A$13="Blueberry")*($B$5:$B$13<0)*($C$5:$C$13<>$L$9)*$B$5:$B$13)
    or
    =SUMIFS($B$5:$B$13,$B$5:$B$13,"<0",$A$5:$A$13,"Blueberry",$C$5:$C$13,"<>"&$L$9)

    L9 = 0 don't sum/count
    L9 <> 0 sum/count
    Last edited by sandy666; 09-07-2017 at 09:25 AM.

  15. #15
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @Sandy666

    Can you please change the cell L9 from a 0 to a 1?
    This SUMPRODUCT will gives 0 then, and I still need a -4 there..
    or is it not possible to get excel to understand I don't want it to look at the cell value I want it to look at what is written into the cell?

  16. #16
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    what should be in L9 to NOT sum/count ?
    and should be compatibile with C column

    NO, FALSE, whatever ?
    Last edited by sandy666; 09-07-2017 at 09:36 AM.

  17. #17
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy666

    It doesn't matter what is in L9. They should never be counted in this calculation. But there is nothing that makes the Blueberries qtty different from Additional blueberries only that in column C they look at different cells to take their value. Thank you for trying.

  18. #18
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    So on the end you not use L6 and L9 but you want SUMIF(S) to get -4 ?

  19. #19
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy666

    I know it doesn't make too much sense like this, as it's out of context. We are estimating weights with the original sheet, so we have all these options as what happens if the "blueberries" are enabled what happens if not what happens if only the "blueberries qtty" are enabled etc. we have a target which from I will need to subtract all the "blueberries qtty" but not the additionals, but nothing makes a difference between the Blueberries Qtty and the Additional Blueberries, only that in column C they look into (in the example) L6 or look into L9 that's why I thought that is the range we could set up a criteria for..

  20. #20
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    you can try this one
    =SUMPRODUCT(($A$5:$A$13="Blueberry")*($B$5:$B$13<0)*($C$5:$C$13<>0)*$B$5:$B$13)
    conditions:
    - Blueberry
    - Values in B column < 0
    - Values in C column <> 0
    independent of L6 & L9
    dependent of values in C column (0 - don't sum, different from 0 - sum)

    Sorry but no more ideas

  21. #21
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy 666

    Yeah thanks for trying but still not exactly.. what I need is
    Conditions:
    - Blueberry
    - C column contains anything but not this "=$L$9"

    Wouldn't depend on C being 0 or 1 and wouldn't depend on L9 being 0 or 1.
    I'm beginning to think it's not possible?

  22. #22
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    ok, I'll try again....

    Conditions to sum:

    A column = Blueberry
    B column = less then 0
    these two are for sure, right?

    any other condition?
    from C column? if needed
    from L9? if needed

    simple english please
    Last edited by sandy666; 09-07-2017 at 10:58 AM.

  23. #23
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy 666

    the only 2 criteria's are:

    A column: "Blueberry"
    C column: if in the cell (look at C13) this is written =$L$9 Don't sum! If there is anything else in it, Sum it!

    Thanks for trying I really couldn't find a solution

  24. #24
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    but C13 has a value from L9 so it can be 0 or 1 or anything else
    =SUMPRODUCT(($A$5:$A$13="Blueberry")*($C$13<>0)*$B$5:$B$13)
    I did for C13<>0 then sum

    $L$9 is an address of the cell NOT value

    what kind of values will be in L9? could you list it?

    btw. the last row (13) should be in the range of SUM?

    another way: range of SUM is: $B$5:$B$13 or $B$5:$B$12
    Last edited by sandy666; 09-07-2017 at 11:19 AM.

  25. #25
    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,054

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Finally, I understand what you want.... I think. Use this array formula:

    =SUMPRODUCT(($A$5:$A$13="Blueberry")*(IFERROR(FORMULATEXT($C$5:$C$13),"")<>"=$l$9")*$B$5:B$13)

    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files

  26. #26
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    maybe too fast but Congrats Glenn

  27. #27
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Glen Kennedy

    YES!!! Thank you!

    This does work!

    Sorry it's hard to explain it in words.

    Can you please explain a little bit what does this formula do? So it does a SUMPRODUCT and what is ISERROR, and that side?

  28. #28
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Sandy666

    Thank you so much for trying!

  29. #29
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    All is well the ends well

  30. #30
    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,054

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    =SUMPRODUCT(($A$5:$A$13="Blueberry")*(IFERROR(FORMULATEXT($C$5:$C$13),"")<>"=$l$9")*$B$5:B$13)

    Red: returns True or False, depending on whether A5:A13 = "Blueberry"
    Orange: returns the text of any formulae in the cell range, or #N/A if no formula
    Cyan: converts any #N/A to blanks, and
    Blue: returns TRUE for anything that isn't"=$L$9" and multiplies it by the first set of true/false: T.T=T, T.F=F, F.F=F, etc


    This returns a series of 0s and 1s in an array {0,0,0,0,0,1,1,0,0} to be exact.

    SUMPRODUCT multiples those numbers by the content of B5:B13 (purple) and adds up the answers....

    Done.

  31. #31
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    @Glenn Kennedy

    Thank you for the explanation, and the solution! I was hoping I could expand the formula myself once I understood it, but I'm struggling to fit it into my original, big sheet. I have modified the example (please see attached) so if the formula in a similar way, wouldn't count when it's =$L$9, =$P$10 and =$P$11..

    Another issue I found is that I thought if I put "Blueberry*" then something can stand beside the blueberry description, and it will be okay to count but I seem to be wrong. Could you help me with that as well?

    Thanks
    Attached Files Attached Files

  32. #32
    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,054

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    I've been going round in ever decreasing circles and can no longer see the wood for the trees.

    This works, but it's ugly:

    =SUMPRODUCT((ISNUMBER(SEARCH("Blueberry",$A$5:$A$15)))*IF((NOT(IFERROR(FORMULATEXT($C$5:$C$15),"")="=$L$10")+NOT(IFERROR(FORMULATEXT($C$5:$C$15),"")="=$p$12")+NOT(IFERROR(FORMULATEXT($C$5:$C$15),"")="=$P$13"))=3,TRUE,FALSE)*$B$5:B$15)

    I need to sit in a dark room for a while...
    Attached Files Attached Files

  33. #33
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: SUMIF formula needs criteria, or help me with another formula please - with example.

    Thank you so much for your effort! This works perfectly!!

+ 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. SUMIF or SUMIF's formula with multiple criteria
    By jackiemariee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-30-2013, 06:19 PM
  2. [SOLVED] Sumif Formula or Sumproduct Formula? Three Criteria.
    By oHUTCHYo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-28-2013, 10:50 AM
  3. SumIF formula with criteria is Text inside a Formula?
    By excellentlearner in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-25-2012, 06:40 PM
  4. [SOLVED] SUMIF :: I don't know how to add another criteria to the formula
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2012, 11:55 AM
  5. [SOLVED] Formula in SUMIF Criteria
    By Zvity in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 04-06-2012, 05:22 AM
  6. Sumif formula with 2 criteria
    By integra in forum Excel General
    Replies: 3
    Last Post: 07-27-2009, 04:47 PM
  7. [SOLVED] SUMIF Formula w/ OR Criteria
    By SJT in forum Excel General
    Replies: 5
    Last Post: 08-04-2006, 12:05 PM

Tags for this Thread

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