+ Reply to Thread
Results 1 to 18 of 18

Count amount of unique values with multiple conditions

  1. #1
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Count amount of unique values with multiple conditions

    Hi,

    I can't succeed to count the amount of unique values with multiple criteria. The columns are employee#, week, year, date and invoicing method.
    Employee#: the employee# occurs so now and then double within a date. Employee# should not be counted if there is more than one unique number on unique date.
    Week: The cutoff date is variable and is set on the first of may for now (Week 18). The search has to be of last month (4 weeks) on date or in the week column, so < week 18 and > week 13
    Year: Year of cutoff date, so 2015.
    Date: Each row has a date. As stated above there are dates with duplicate employee#'s.
    Invoicing method: Should only be counted when "YES"

    There has been already a similar post about this issue but I can't seem to comprehend it and apply it on my sheet.

    Anyone fancy helping out?
    Please find attached an Example.xlsx.


    Looking forward to the responses.
    Edit: Right answer is 6.
    The rows that apply to the criteria are:
    5 (regular)
    6 (or 7 since it is a duplicate with same date)
    9 ( Same employ# but seperate date)
    10 (Same employ# but seperate date)
    12 (Different employ# same date)
    13 (Different employ# same date)
    Last edited by Melon6; 05-21-2015 at 03:34 AM. Reason: Wrong count

  2. #2
    Forum Contributor jayajaya_4's Avatar
    Join Date
    05-09-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    259

    Re: Count amount of unique values with multiple conditions

    =COUNTIFS(B7:B18,"yes",D7:D18,D9,C7:C18,"<18",C7:C18,">13")

  3. #3
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Winterville, NC
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Count amount of unique values with multiple conditions

    I need a little clarification. Are you saying employee ID 5 shouldn't be counted since they're both on 4/6/15 but employee ID 7 should because they are on separate dates? I don't come up with 5 that's why I'm asking. I come up with 2 (if we're not counting #7) or 4 if we are counting #7.

    Why are you including week 13? To me, 5/1 minus 4 weeks only goes back to 4/3. I'm only asking for clarification as I work through the math
    Last edited by acroley1; 05-19-2015 at 09:59 AM.

  4. #4
    Forum Contributor jayajaya_4's Avatar
    Join Date
    05-09-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    259

    Re: Count amount of unique values with multiple conditions

    I am not sure ur criteria are bit confusing

  5. #5
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Thanks for your response, however nope. Nice try
    By the way you probably tried: =COUNTIFS(B2:B18;"yes";D2:D18;D9;C2:C18;"<18";C2:C18;">13") which results in 7 and is incorrect.

  6. #6
    Forum Contributor jayajaya_4's Avatar
    Join Date
    05-09-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    259

    Re: Count amount of unique values with multiple conditions

    can u post the criteria to be matched

  7. #7
    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,053

    Re: Count amount of unique values with multiple conditions

    Maybe with a helper column...
    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.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  8. #8
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Quote Originally Posted by acroley1 View Post
    I need a little clarification. Are you saying employee ID 5 shouldn't be counted since they're both on 4/6/15 but employee ID 7 should because they are on separate dates? I don't come up with 5 that's why I'm asking. I come up with 2 (if we're not counting #7) or 4 if we are counting #7.

    Why are you including week 13? To me, 5/1 minus 4 weeks only goes back to 4/3. I'm only asking for clarification as I work through the math
    Excuse me for the inconvenience, I noticed that my set up was wrong. I'm going to fix the example asap.

    You are right in your first sentence: employ# 5 is not counted twice because it is on the same date. (side fact; the lad worked on two different things on that day)
    Employ# 7 should be counted since he worked on two separate dates. I'm trying to count the total amount of days a employ# worked.
    Week 13 is added just to check if your formula is correct

    So concluding for more information:
    The rows that apply to the criteria are:
    5 (regular)
    6 (or 7 since it is a duplicate with same date)
    9 ( Same employ# but seperate date)
    10 (Same employ# but seperate date)
    12 (different employ# same date)
    13 (Different employ# same date)

  9. #9
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Winterville, NC
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Count amount of unique values with multiple conditions

    Are you opposed to adding a column?

    Also I get a lower # because I used the cutoff date and went back 4 weeks vs using week# which was going back 6 weeks. Easily fixed with futher clarification on the needs of the spreadsheet.
    Attached Files Attached Files

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

    Re: Count amount of unique values with multiple conditions

    On my first effort, I grouped individual and weeknumber in the helper. It now transpires that it should have been individual and date (which would give the answer 6). The attached now does that...
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Quote Originally Posted by acroley1 View Post
    Are you opposed to adding a column?

    Also I get a lower # because I used the cutoff date and went back 4 weeks vs using week# which was going back 6 weeks. Easily fixed with futher clarification on the needs of the spreadsheet.
    Adding a column should be avoided but if it's necessery I am not against it. Ill put it somewhere in the back of the sheet.
    But I think Glenn hit it right. Check his answer. Thanks for the help

  12. #12
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Quote Originally Posted by Glenn Kennedy View Post
    On my first effort, I grouped individual and weeknumber in the helper. It now transpires that it should have been individual and date (which would give the answer 6). The attached now does that...
    Thanks for the help Glenn.
    I didn't experiment with added columns enough it seems. Going to test it on my sheet now.

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

    Re: Count amount of unique values with multiple conditions

    Thanks. There are probably ways round it, but if it keeps a more manageable and easily maintained formula, is it worth it?? You can always just hide the column that it's in...

  14. #14
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Winterville, NC
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Count amount of unique values with multiple conditions

    My only concern with the equation Glenn Kennedy posted is that you have to hard code the >13 and <18. I think those should be linked to J2 and L2 using ">"&J2 and "<"&L2 respectively. Also, as this isn't a table, adding rows of data will require the equation to be updated. You could 1) format as a table and update equation one time (versus every time) to look at the table ranges; 2) update the columns in the COUNTIFS equation to be the full column (ie $B:$B vs B2:B13)...however, if you're data gets very large, this could slow things down.

    Just my opinions to make the equation a bit stronger with less rework as data is added.

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

    Re: Count amount of unique values with multiple conditions

    Fair enough comment about using cell references, and about susing a structured tabble. However, there's no reason not to use whole-column references with countifs; so the formula I suggested could just as efficiently be phrased as:=COUNTIFS(B:B,"=Yes",C:C,">13",C:C,"<18",F:F,"=1")

  16. #16
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Good that you mentioned. I will apply the variable week numbers.
    about 1) I added the row to my data sheet. The data sheet is the foundation of a lot pivot tables. If I format the data sheet as a table, will it be capable of updating the pivots?
    2) Very true. I tried applying the function but the data is large indeed. It's currently stuck since I tried applying the function to the whole column.
    Ill try again in a few to see if it's just a coincidence. What's your suggestion?

  17. #17
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Winterville, NC
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Count amount of unique values with multiple conditions

    My suggestion is to definitely use table format. I have only begun to find the benefits of that format over the last few months and I'll never go back now!!!!

    1) Pivots definitely work off tables. Actually, pivots work better on tables because you don't have to keep updating your data range with the "change data source" button as you add data. If it's in table format the range will update to the entire table whenever you click "refresh all"....I LOVE this feature as I hated updating ranges.

    2) If you don't want to use the whole column as the range (I have run into some issues), once you format as a table, just update the range to the new table range. Now does that sentence make sense? No...here's an example using your data:
    *change the data in A1:A13 to be formatted as a table
    *go to the countifs formula in N6 and delete the B2:B18 for the first criteria range.
    *highlight B1:B13...it will update in the fomula to say "Table1[[#All],[Invoicing method]]"
    I did it in this attachment --- Example.xlsx


    Benefits:
    *"Table1[[#All],[Invoicing method]]" is like a named range...so no matter how many rows you add...as long as you add them into the table, the formula will keep updating
    *the formula in column F will keep filling in as you add data
    *use "refresh all" and your pivots will auto update after you add data (note: since your pivots are already set up, you might have to do "change data source" one time and set it to the table range. Then you should be good after that. Maybe that'll be unnecessary...I'm not sure.

    I love tables!
    Last edited by acroley1; 05-19-2015 at 11:43 AM.

  18. #18
    Registered User
    Join Date
    04-20-2015
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2010
    Posts
    16

    Re: Count amount of unique values with multiple conditions

    Thanks for the tips!
    Going to apply it tomorrow.

+ 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] Count only unique values with two conditions
    By Melon6 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-01-2015, 05:24 AM
  2. Count unique values with multiple conditions
    By liybpg in forum Excel General
    Replies: 6
    Last Post: 03-18-2015, 05:43 AM
  3. Count Unique Values With Multiple Conditions, Array Method
    By 5150 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-28-2014, 04:37 PM
  4. [SOLVED] count the number of unique values given certain conditions
    By eh308701 in forum Excel General
    Replies: 8
    Last Post: 05-31-2012, 11:48 PM
  5. Count unique logs with multiple conditions of multiple sheets
    By Robert Bob in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-12-2007, 12:49 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