+ Reply to Thread
Results 1 to 18 of 18

If + sum + countiif

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    If + sum + countiif

    Hi, I'm trying to get the total cost per company- Please see attachment with sample data.
    there are two sets- apples and oranges use only set1 and bananas and cherries use set 2. How can I get the sum of each unique fruit for each unique company, to get the total cost?test.xlsx
    Last edited by cs02; 09-10-2015 at 03:54 PM.

  2. #2
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: If + sum + countiif

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

    Regards

  3. #3
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    How can I get it to change for difference companies? my original data has hundreds of companies.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: If + sum + countiif

    This gives the toal for each unique fruit by unique company

    =SUMPRODUCT(($B$2:$B$12=B2)*($A$2:$A$12=A2)*($C$2:$C$12+$D$2:$D$12)*$E$2:$E$12)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    It doesnt seem to work- Im getting different values for the same company.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: If + sum + countiif

    It doesnt seem to work- Im getting different values for the same company.
    and the same exact fruit?

    Even though you say "Unique Fruit" do you mean Set of fruit, as in Apples and Oranges is a set and Banannas and cherries is a set?

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: If + sum + countiif

    It would probably be better to upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: If + sum + countiif

    I have the sheet from the first post but it doesn't have expected results so I guess I am missing something.

  9. #9
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    Yes- so the total for every unique fruit- I have multiple entries because the days change- but even if there are multiple apples- I want just one of it, because the cost is same. So in G2 I need 5*12 + 3*9 + 2*15 +3*10 to get the total for the first company (G3-G7 could be blank or same values.. doesnt matter). and in G8 I need 4*12 +7*15. similarly in G11 I need 11*9 + 14 *12 for company 3.
    Hope that makes sense?
    Last edited by cs02; 09-11-2015 at 09:12 AM.

  10. #10
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    Yes- so the total for every unique fruit- I have multiple entries because the days change- but even if there are multiple apples- I want just one of it, because the cost is same. So in G2 I need 5*12 + 3*9 + 2*15 +3*10 to get the total for the first company (G3-G7 could be blank or same values.. doesnt matter). and in G8 I need 4*12 +7*15. similarly in G11 I need 11*9 + 14 *12 for company 3.
    Hope that makes sense?

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: If + sum + countiif

    Okay, so it's the sum for each company (all fruits)

    Try this copied down

    =IF(COUNTIF($A$2:$A2,A2)=1,SUMPRODUCT(($A$2:$A$12=A2)*($C$2:$C$12+$D$2:$D$12)*$E$2:$E$12),"")

  12. #12
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    That gives me 237 for G2, whereas it should be 147. Also- set1 may not always be 0 for bananas or cherries, but only set 2 has to be considered so adding C and D wont work for that case

  13. #13
    Registered User
    Join Date
    07-20-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    35

    Re: If + sum + countiif

    @ChemistB: Perhaps we can do 2 countifs-one on A, like you did in the formula and another countif on B- to get one of each fruit. and then put an IF statement inside sumproduct to check if its apples or oranges so that multiplication of the sets can be done accordingly? Not sure how that would be written down though. Thanks for your help!!

  14. #14
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: If + sum + countiif

    I'm trying to figure out how to remove the duplicates (i.e. row 2 and 3). That's the tricky part. You're right, I think we can work around the set A and Set B thing telling Excel to only look in col C for Apples and Oranges for example.

  15. #15
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: If + sum + countiif

    I've hit a different snag.

    This will give me correct amounts for every company except company2.

    =IF(COUNTIF($A$2:A2,A2)=1,SUMPRODUCT(--(A2=$A$2:$A$12),IF(($B$2:$B$12="apples")+($B$2:$B$12="orange"),$C$2:$C$12,$D$2:$D$12),$E$2:$E$12),"")

    I keep getting 48. Can't make it budge.

    Anybody see anything?
    Dave

  16. #16
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: If + sum + countiif

    hi cs02. try this array formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    copy down the cells.
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  17. #17
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: If + sum + countiif

    Hi Dave

    You assume that your formula, in this part IF(($B$2:$B:$12)="apples" gives as a result {1,1,0,0,0,0,1,0,0,0,1} .
    Excel calculates that part as just ($B$2="apples").
    So, for company1 IF(($B$2:$B$12="apples")+($B$2:$B$12="orange") gives as result True+False, i.e. 1 for all formulas.

    Regards

  18. #18
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: If + sum + countiif

    Quote Originally Posted by José Augusto View Post
    Hi Dave

    You assume that your formula, in this part IF(($B$2:$B:$12)="apples" gives as a result {1,1,0,0,0,0,1,0,0,0,1} .
    Excel calculates that part as just ($B$2="apples").
    So, for company1 IF(($B$2:$B$12="apples")+($B$2:$B$12="orange") gives as result True+False, i.e. 1 for all formulas.

    Regards
    Thank you José for looking at this. I see it, now. Apples, orange, bananas and cherry are irrelevant.

+ 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