+ Reply to Thread
Results 1 to 11 of 11

Count function with multiple qualifying criteria

  1. #1
    Registered User
    Join Date
    07-27-2018
    Location
    San Francisco, CA
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    6

    Count function with multiple qualifying criteria

    count.JPG

    Banana, apple, orange are all considered fruit.

    I need to count the number of people who ate fruit during lunch, and the answer should be 3.

    Please help. Thanks in advance.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Count function with multiple qualifying criteria

    It is always better to include a sample workbook so people do not have to duplicate your work. Also, somewhere, you have to tell the application what fruit is. This will probably involve the find command and an array formula, but I'll wait to see the data.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    07-27-2018
    Location
    San Francisco, CA
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    6

    Re: Count function with multiple qualifying criteria

    Thanks for the instructions. I just uploaded Fruit.xlsx
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Count function with multiple qualifying criteria

    Here is one way to do it, but I am not satisfied. Although you can have as many people as you want and they can eat anything they want, there is not much flexibility if you add a new fruit to the menu. You would have to add another column with a specific formula. I'll post it for now, but I will continue to work on a more general solution: on that gives the answer by referencing the orange (in color) table. I would like to do this with an array formula. If can be done relatively easily in VBA.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Count function with multiple qualifying criteria

    Your best for doing this is creating a table to establish what food item is what category of food. Then in your input, having each item in its own column for a given person instead of the same cell. That would make it pretty easy to do, easy to add additional food items/categories, and deal with higher numbers of food items per person than is reasonable.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  6. #6
    Registered User
    Join Date
    07-27-2018
    Location
    San Francisco, CA
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    6

    Re: Count function with multiple qualifying criteria

    Quote Originally Posted by dflak View Post
    Here is one way to do it, but I am not satisfied. Although you can have as many people as you want and they can eat anything they want, there is not much flexibility if you add a new fruit to the menu. You would have to add another column with a specific formula. I'll post it for now, but I will continue to work on a more general solution: on that gives the answer by referencing the orange (in color) table. I would like to do this with an array formula. If can be done relatively easily in VBA.

    Thank you for the wonderful solution. I'm very satisfied with it, and I actually would prefer to stick with Excel instead of going through VBA. Thanks again!

  7. #7
    Registered User
    Join Date
    07-27-2018
    Location
    San Francisco, CA
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    6

    Re: Count function with multiple qualifying criteria

    Quote Originally Posted by Zer0Cool View Post
    Your best for doing this is creating a table to establish what food item is what category of food. Then in your input, having each item in its own column for a given person instead of the same cell. That would make it pretty easy to do, easy to add additional food items/categories, and deal with higher numbers of food items per person than is reasonable.
    Thanks for your input.

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Count function with multiple qualifying criteria

    I gave up on the array formula for a while. Here is a VBA implementation. With this function, you can add people, they can eat whatever they want and you get to decide what fruit is on the orange table.

    I converted your data into a table: Table_Lunch and I put the fruit in another table: Table_Fruit. These names are used in the code. You do not need the helper columns with this code.

    Here is more information on tables: http://www.utteraccess.com/wiki/Tables_in_Excel.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Count function with multiple qualifying criteria

    I got it using formulas only (with tables and named ranges for ease), should also be very easy to add new fruits and categories. I also provided a results sheet with drop downs to get the results of any food item and any category you want.

    See attached.

    I have 4 new sheets. Lists is just the list of categories, simply add new items directly under last and the list will grow. The drop downs for category in the file are based on this list.

    The Key sheet is a table that relates food item to category, IE how Excel will know an apple is a fruit. Simply enter a new food item directly under the last and use the drop down for category to select its category.

    The input sheet is where you place a person and their selections of food item. I have provided 7 columns, it should be very feasible to use more or less. At the right side of this input table are the magic formulas. The 1 is simply a count of the food items on that row matching the desired item to lookup from the Results sheet B2 (as saved "apples"). The next column counts how many items on that row are of the desired category selected on Results D2, using the Key table to determine what food items match what category.

    The results sheet provides a count by # of people who had the food item or the category of food and also a total count of that food item and category.

    Let me know if you have questions
    Attached Files Attached Files
    Last edited by Zer0Cool; 07-27-2018 at 05:04 PM.

  10. #10
    Registered User
    Join Date
    07-27-2018
    Location
    San Francisco, CA
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    6

    Re: Count function with multiple qualifying criteria

    Thank you guys so much for taking the time to help me with this. I can see this forum is a great resource. If I have any follow-up questions, I won't hesitate to ask. Keep up the good work!

  11. #11
    Forum Contributor
    Join Date
    10-30-2003
    Location
    Singapore
    MS-Off Ver
    Excel 2019
    Posts
    197

    Re: Count function with multiple qualifying criteria

    Perhaps,

    Put this in D10 :

    =SUMPRODUCT(--(COUNTIF(D2:D6,{"*banana*","*apple*","*orange*"})>0))

    Regards
    Bosco

+ 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. Replies: 6
    Last Post: 10-21-2015, 09:44 AM
  2. A formula to count subtotals if they meet a qualifying condition
    By JC_LA_1979 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-16-2015, 01:03 PM
  3. [SOLVED] Weighted Average with Multiple Qualifying Criteria
    By bpiereder in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-17-2014, 03:31 PM
  4. Multiple Criteria Function along with Count function
    By Joseph Wee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-23-2013, 12:51 AM
  5. Index and IF formula with multiple qualifying criteria
    By NadaNoodle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-04-2012, 08:53 AM
  6. Using multiple criteria for joint COUNT and IF Function
    By barkaroo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-04-2010, 05:18 PM
  7. multiple criteria in count function
    By sayasimpson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-15-2007, 04:54 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