+ Reply to Thread
Results 1 to 20 of 20

Possible to use SUMIF and COUNTIF together? Or other solution?

  1. #1
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Possible to use SUMIF and COUNTIF together? Or other solution?

    Been banging my head against Google trying to figure this out.

    I've made a Workbook that has a data set that it pulls, let's say, Store Name and Item Inventory. I have checkboxes that when checked will tally up the sum of what is in inventory in one column and what the sum of what was sold in another.

    Then I have a column with actual inventory item names - like Apples and Oranges. What I'm trying to do is write a formula so that if the checkbox is "TRUE" then it will sum up what is in inventory/sold according to the item. So if "Store1" and "Store3" are checked it pulls how much total inventory and total sales into two columns, then in a third column will break it down by item.

    So the formula is a SUMIF, but I also want it to look at the Data sheet to cross reference what's in B2 (Apples). So kind of like a COUNTIF Data!$C:$C,$B$2 and if that matches then provide the sum from the checkboxed stores.

    Attached is a sample sheet I am trying to get it to work on.

    Sorry if my explanation is confusing but any advice is greatly appreciated!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Figured it out, so nevermind! :D

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,215

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    So I thought that I had this figured out, but it turns out that I don't. I made a little progress but now it is tallying everything in the column without using the criteria. Attached is an example of a couple different ways I tried to solve this, but for some reason it's ignoring the reference criteria.

    I've been spending hours trying to figure this out so was actually going to pay a "Guru" here to help but it seems their PayPal is not active anymore. Any help would be greatly appreciated.
    Attached Files Attached Files

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,215

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    OK - help us out here! What are your expected results (and why) and where should they appear?

  6. #6
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    On the Spreadsheet I just attached, I am trying to get it so I can see which "Source" is selling the most of a product (Apples, Oranges). I usually have many "Sources" but sometimes just want to compare a few sources, which is why I made the "TRUE"/"FALSE" checkboxes. So, for example, I could just see how "Source1" and "Source2" are doing as a whole together by checking their checkboxes.

    So in the attached data sheet you can see that there are actually only 11 "Apples" and none have "Sold", but the formula is showing 28 "Apples" and 7 "Sold" because it is tallying all the Sources that are checked in the checkbox but not actually looking for "Apples".

    I hope that makes sense!

  7. #7
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Actually, this Spreadsheet may make more sense because I changed some labels.
    Attached Files Attached Files

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,215

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    No, not really!

    Which formula are you referring to? There are two places where 28 and 7 are showing - which cells are we looking at, please?

  9. #9
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    You can ignore F5 and F6 - those are just an overall total of what is checked in the checkbox. I'm trying to get C4 and C5 to just show how many "Apples" are coming from each checked source. Instead C4/C5 is basically just tallying everything instead of filtering out just "Apples". In fact,my formulas are not even trying to tally the other items such as "Oranges", "Pickles", "Melons", and "Grapes".

    One solution I thought would work is =IF(COUNTIF( Data!$C:$C,$B$3), SUMIFS($J2:$J4,$I2:$I4,"TRUE"), "")

    The other I thought would work is =SUMIFS($J:$J,Data!$C:$C,$B3)

    But neither of those formulas seem to be taking B3 into account.

  10. #10
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    C4, an array formula:
    =SUM(COUNTIFS(Data!D:D,'Store 1'!$B$2,Data!E:E,B4,Data!C:C,'Store 1'!$B3,Data!B:B,IF($G$2:$G$4=TRUE,{"Source1";"Source2";"Source3"})))

    copied down to D4. Select both cells, and copy paste into C7, C10, etc. Change B12 to Melon (not melons).




    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...

    PLEASE take a moment to amend your profile to show us where you are in the world. NA doesn't mean anything. Also - you are CLEARLY NOT using Excel 2003. Amend.
    Attached Files Attached Files
    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

  11. #11
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Slight change in plan!!

    C4:
    =SUM(COUNTIFS(Data!D:D,'Store 1'!$B$2,Data!E:E,B4,Data!C:C,'Store 1'!$B3,Data!B:B,IF($G$2:$G$4=TRUE,$F$2:$F$4)))

    D4:
    =SUM(COUNTIFS(Data!D:D,'Store 1'!$B$2,Data!E:E,B5,Data!C:C,'Store 1'!$B3,Data!B:B,IF($G$2:$G$4=TRUE,$F$2:$F$4)))

    Select both... etc,etc.

    Also delete s from grapes
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Sorry about the profile, I hadn't looked at it since 2011 so forgot it wasn't filled out. I just updated it.

    It seems like your Array formula worked but I ran into one problem with it - I usually deal with about 100+ "Sources" (like Source1 and so on). Is there anyway to have the formula look down the entirety of G:G for "TRUE" and do the same calculations as your formula did but not having to have "Source1" and so on in the actual formula?

    Thanks again for your help.

  13. #13
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    That occurred to me while I was... cutting down a tree. See post 11.

  14. #14
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Ah-ha! In your post #11 would it be possible to change ($G$2:$G$4=TRUE,$F$2:$F$4) to ($G:$G=TRUE,$F:$F) so it goes down all of both columns, or will I just have to specify how far down it checks?

    Yours seems like a great solution though!

  15. #15
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Don't use whole column ranges in array formulae... unless you want to grow old waiting for it to calculate. Do you really have more than 1,000,000 rows of data??

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

  16. #16
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    I've contradicted myself... haven't I. Don't use whole column references in thsi formula... at all. Change them to "reasonable" sensible fixed ranges, or use dynamic named ranges.

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,215

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Or change your data into Excel tables.

  18. #18
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    Ok, I think with all your help I have almost everything sussed out. One more thing that is probably pretty easy but my brain is fried after working on this all night.

    So in C4 (Bought) technically that should tally what was Sold as well, since the Bought number would be the total amount started out with. That would give a true conversion factor of I had a total of X amount, sold Y amount so the conversion of sales is Z amount. Would that be easy to add to the formula?

    Sorry if that doesn't make sense...like I said, brain=fried right now.

  19. #19
    Registered User
    Join Date
    10-03-2011
    Location
    WA, USA
    MS-Off Ver
    Excel 2016
    Posts
    10

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    I guess probably the easiest was would be to just add +C5 to the end of your formula for C4!

  20. #20
    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,099

    Re: Possible to use SUMIF and COUNTIF together? Or other solution?

    I'm not sure if I follow what you're saying in the last two posts... You must be fried!!

+ 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. [SOLVED] SUMIF and HLOOKUP or another solution?
    By might_be_high in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-26-2017, 01:00 PM
  2. [SOLVED] SUMIF or better solution
    By szabodomokos in forum Outlook Formatting & Functions
    Replies: 8
    Last Post: 08-29-2017, 04:40 AM
  3. [SOLVED] Solution for SUMIF
    By aaaaaaiden in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-19-2014, 06:26 AM
  4. COUNTIF? Or a better solution?
    By crevalle in forum Excel General
    Replies: 5
    Last Post: 08-18-2011, 02:02 PM
  5. COUNTIF solution
    By jaywerth in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-24-2007, 04:06 PM
  6. Proper solution?:sumif
    By Nuno Jácome in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2006, 11:55 AM
  7. solution: SUMIF
    By Dahlman in forum Excel General
    Replies: 1
    Last Post: 06-09-2005, 04:05 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