+ Reply to Thread
Results 1 to 19 of 19

Combining COUNTIFS with VLOOKUP?

  1. #1
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Combining COUNTIFS with VLOOKUP?

    Hi All,

    Need your help in coming up with a formula that does a count by site of the number of objects that are between a certain range. Not sure if it's a Countif statement with a vlookup or an IF statement with a Countif with a vlookup?

    The ranges are:

    0 to -5
    -6 to -10
    -11 to -30
    -31 to -50
    -51 to -100


    0-5
    6-10
    11-30
    31-50
    51-100

    Please see attached example file.

    Any help is appreciated.

    Thank You.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Combining COUNTIFS with VLOOKUP?

    So what does your expected output look like?

    I have one idea, but I dont want to waste time on it if you want the output to look like something else.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Hi Special-K,

    Appreciate your quick response.

    Ideally what I would like is to have by site, what the counts would be for the different ranges.

    Feel free to adjust the ranges if you think it makes more sense.

    Thanks.

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Combining COUNTIFS with VLOOKUP?

    this could work for you, adjust for each range as needed...
    =SUMPRODUCT(($C$2:$C$123>=0)*($C$2:$C$123<=0.05))

    And this (adjust again for ranges) for your negatives....
    =SUMPRODUCT(($C$2:$C$123<=0)*($C$2:$C$123>=-0.05))
    Last edited by Sam Capricci; 06-07-2018 at 12:15 PM.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

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

    Re: Combining COUNTIFS with VLOOKUP?

    An example of what you want the results to look like would help. Looking at what you posted I would expect you are asking to have a summary where for each unique site you have a count of records within each range you defined. Depending on the size of your actual data set this could be very large. Right now its 10x "columns" for the ranges and a row for x number of unique sites.

    The SUMPRODUCT above will give you total count within a range, not by site (as far as I can tell). You could extend SUMPRODUCT to do this, but if I have understood what you asking for a COUNTIFS will do the trick as well.

    Am I correct in my undertanding, that the results may be say another sheet (a summary sheet) with a layout like:

    sites | range 0-5 | range 6-10 | range 11-30 | etc...
    10010 | 2 | 4 | 6 | etc...
    10021 | 6 | 13 | 2 | etc...
    10026 | 7 | 1 | 0 | etc...
    etc..

    EDIT: Also, its very unusual to combine a VLOOKUP with formulas like COUNT/SUM/AVERAGE as VLOOKUP is a lookup type function that returns a single value from a place, whereas the other functional are mathematical and typically are most viable when given more than 1 numeric value. They both serve very different purposes depending on what you want to return. Generally if you are dealing with numeric values and need to analyze/summarize them (with or without conditions) then you want a variation of SUM/COUNT/AVERAGE/SUMPRODUCT etc. On the other hand if you need to return an existing value in a field given some criteria, then a lookup function like VLOOKUP or INDEX is what you would use.
    Last edited by Zer0Cool; 06-07-2018 at 12:15 PM.
    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
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Thanks Zer0Cool,

    That's exactly the result I am looking to achieve on a summary sheet. My apologies if I wasn't clear enough.

    I know the result might be overwhelming, but I can adjust the ranges to minimise that.

  7. #7
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Combining COUNTIFS with VLOOKUP?

    Nice catch Zer0Cool, can't always tell from what is written what they really want, guess I missed the mark.

  8. #8
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    My apologies for not being clear enough Sambo kid

  9. #9
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Combining COUNTIFS with VLOOKUP?

    Not your fault, I've had problems at times with reading comprehension on this site.
    Just glad someone got you what you wanted.

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

    Re: Combining COUNTIFS with VLOOKUP?

    Ok, is your list of unique sites static or ever changing? IE: 10010, 10021, etc. are they always in this file (at least 1 time) or do new ones get added and/or old ones get removed? Also how many records are we talking about total, 100 rows, 1,000, 100,00?

    Is this a 1 time thing or does this file get updated periodically and you will need to update the summary? If its updated, whats the process (is it a new file each time, if its the same file to you overwrite or append new entries, etc.)?

    The answer above really determines how you get the unique list. If the list is pretty static in terms of unique sites, I just copy that column to another sheet and use remove duplicates on it to get my unique ID's, then create my headers and start on formulas. If that list is ever changing, I have to decide how much effort is needed and what approach is best for generating that unique list.

    If its a new file every time I would likely create a macro and store it in my personal workbook or save it as an addin to use across the new files. If its the same file, data is appended and the unique ID's dont change, then I likely dont have to touch the summary sheet after its been setup, just use dynamic named ranges for the data or have the data placed in a table (the Excel feature, which expands with the data and uses structured references). If its the same file but the Unique ID's vary I might consider a Pivot Table or a combination of some macro code and formulas.

    With a bit more info I could give you a more specific answer

  11. #11
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Thanks again for the explanation. Still a student of excel.

    Is it possible for you to compose the formula for me that would give the desired result I need? I tend to get confused when trying to do to put together something like this.

    Appreciate it.

    Thanks.

  12. #12
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Hi Zer0Cool,

    The list is static and this is a one time exercise.

    Hope this make it simpler.

    Thanks.

  13. #13
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Hi Zer0Cool,

    I am hoping that since the list is static and it's a one time analysis I need to do with the data, this makes it a bit less complicated for you to do the formula.


    Thanks again.

  14. #14
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Combining COUNTIFS with VLOOKUP?

    Maybe this is what you want based on the replies so far?
    I used sumproduct in various ranges and you can adjust them to continue.
    Attached Files Attached Files

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

    Re: Combining COUNTIFS with VLOOKUP?

    See attached.

    First thing to point out is your ranges overlap, so we have to make a choice about where the break points are. In my sample its as follows:

    < 0, >= -5
    < -5, >= -10
    < -10, >= -30
    < - 30, >=-50
    < -50, >= -100

    >= 0, < 5
    >= 5, < 10
    >= 10, < 30
    >= 30, < 50
    >= 50, <= 100

    Also note your numbers are percentages, not whole numbers, thus 5 = .05, 10 = .1, 100 = 1, etc. You will see the conversion highlighted on the Ranges sheet/table

    The COUNTIFS I used, will have put my foot in my mouth as I did actually combine it with VLOOKUP in this case since I am looking up the start/end of the desired ranges as thats not part of your actual data and its easier to get it from another table or key than it is to split apart the headers for those criteria values. Its basically 3 parts/criteria; the site, greater than and less than the bounds of the range for that column. As you can see from the subtotals and grand totals they match your data set.

    I even added a filter to your data set so you can filter down to the site and range and compare the result to the formulas (this is how I verified my results).

    SUMPRODUCT is one of my favorite functions as its extremely powerful and versatile. It should however be reserved for when another purpose built function cannot do the same job. A COUNTIF(S)/SUMIF(S)/AVERAGEIF(S) will always be more efficient (in terms of calc time and stress on the calc chain) as noted here (specifically under the "Optimize array formulas and SUMPRODUCT" and "Consider options for using SUM for multiple-condition array formulas" headings.)

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

  16. #16
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Thank you Sambo kid for your suggestion. Much appreciated!

    Unfortunately, because my dataset was quite large, I found Zer0Cool's suggestion worked much better.

    But, thanks again for your time!
    Last edited by jeptik; 06-08-2018 at 11:22 AM.

  17. #17
    Forum Contributor
    Join Date
    09-08-2016
    Location
    Canada
    MS-Off Ver
    MS365 Version 2401
    Posts
    127

    Re: Combining COUNTIFS with VLOOKUP?

    Zer0Cool,

    Your recommendation worked like a charm!

    Thank you for that and all the other nuggets you offered along the way.

  18. #18
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Combining COUNTIFS with VLOOKUP?

    glad you got your solution AND thank you for the rep!

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

    Re: Combining COUNTIFS with VLOOKUP?

    Glad it worked out for you and thanks for the rep as well.

+ 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] Combining COUNTIFS with VLOOKUP
    By jeptik in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 05-01-2017, 08:31 AM
  2. [SOLVED] Combining COUNTIFS and ISNUMBER
    By OverKnight in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-05-2015, 12:55 AM
  3. Combining Indirect with Countifs
    By arthurphil in forum Excel General
    Replies: 7
    Last Post: 01-27-2015, 08:13 AM
  4. [SOLVED] Combining CountIfS Formulas
    By Phil Hageman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-21-2013, 09:25 AM
  5. Combining COUNTIFS and OR function
    By tatyanamarie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-12-2013, 08:51 AM
  6. [SOLVED] Combining two COUNTIFS
    By fletch8701 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-19-2012, 11:07 PM
  7. Replies: 0
    Last Post: 12-16-2011, 09:01 AM

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