+ Reply to Thread
Results 1 to 12 of 12

Need to return the earliest date respective to one criteria

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Need to return the earliest date respective to one criteria

    Hello, I have a list of names and a list of dates respective to each time that employee has participated in a certain event. I need another column to return the earliest event that employee has participated, or better yet, return a "1" in the row if that was the earliest event that employee has participated in. For example, the table below lists the employee name, the date of an event they participated in, and column C, which would be my expected result. For C2, formula would compare all dates respective to "Bill", then return a "1" if the date in that row was the earliest of all the events listed. Please help!

    A________B________C
    NAME____DATE_____EARLIEST?
    Bill..........1/4/12..........0
    Bill...........3/2/11.........1
    Joe..........5/23/12.......0
    Bob.........2/2/12..........1
    Joe..........4/15/11........1
    Bob..........6/12/12.......0

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Need to return the earliest date respective to one criteria

    Try with this ARRAY formula.

    =if(b2=min(if($a$2:$a$100=a2;$b$2:$b$100));1;0)

    UNTESTED
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by Fotis1991 View Post
    Try with this ARRAY formula.

    =if(b2=min(if($a$2:$a$100=a2;$b$2:$b$100));1;0)

    UNTESTED
    Thanks for your input, but this doesn't quite work. The "min" function needs a range to work from, and your second "if" function does not provide the necessary range to compare values. This formula returned a "0" for every instance.

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Need to return the earliest date respective to one criteria

    =MIN(IF($A$2:$A$100=A2,$B$2:$B$100))=B2

    Ok. This one gives TRUE or FALSE, as results. Does this works for you?

    and this one gives the numbers that you want.

    =IF(MIN(IF($A$2:$A$100=A2,$B$2:$B$100))=B2=TRUE,1,0)
    Last edited by Fotis1991; 04-08-2013 at 11:01 AM.

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need to return the earliest date respective to one criteria

    For a "non-array" version try COUNTIFS, e.g. in C2 copied down

    =(COUNTIFS(A:A,A2,B:B,"<"&B2)=0)+0
    Audere est facere

  6. #6
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by Fotis1991 View Post
    =MIN(IF($A$2:$A$100=A2,$B$2:$B$100))=B2

    Ok. This one gives TRUE or FALSE, as results. Does this works for you?

    and this one gives the numbers that you want.
    Not quite...I'm getting "FALSE" returned for every instance, when some should be "TRUE". I'm also a bit confused by this formula, I think there might be an error because the "IF" statement is checking to see if the name matches. If the name does not match, it returns the entire array for the MIN function to sort through. However, I think it needs a smaller array to sort through for the case that the name DOES match. For example, add a date to a smaller array for only cases when the name matches criteria, then take the MIN of that smaller array...I'm just not sure how to do that.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need to return the earliest date respective to one criteria

    The MIN(IF formula works for me.....but you need to enter the formula with CTRL+SHIFT+ENTER so that curly braces like { and ] appear around it.....or try my COUNTIFS suggestion which can be entered normally

  8. #8
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by daddylonglegs View Post
    For a "non-array" version try COUNTIFS, e.g. in C2 copied down

    =(COUNTIFS(A:A,A2,B:B,"<"&B2)=0)+0
    This worked! Thanks for your help. Why does the formula need quotations around the < sign and what the "&" do?

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by BYizz View Post
    Why does the formula need quotations around the < sign and what the "&" do?
    All the "IFS" functions like COUNTIF, SUMIFS, AVERAGEIFS etc. use text strings as criteria, hence the quotes, so for "greater than 10" you'd use ">10", but if you have 10 in a cell, e.g. G2 then you need to concatenate the ">" to the 10 so & does that, e.g. ">"&G2

  10. #10
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by daddylonglegs View Post
    All the "IFS" functions like COUNTIF, SUMIFS, AVERAGEIFS etc. use text strings as criteria, hence the quotes, so for "greater than 10" you'd use ">10", but if you have 10 in a cell, e.g. G2 then you need to concatenate the ">" to the 10 so & does that, e.g. ">"&G2
    Good to know. Thanks!

  11. #11
    Registered User
    Join Date
    10-04-2012
    Location
    Panama City, Florida
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Need to return the earliest date respective to one criteria

    Quote Originally Posted by daddylonglegs View Post
    For a "non-array" version try COUNTIFS, e.g. in C2 copied down

    =(COUNTIFS(A:A,A2,B:B,"<"&B2)=0)+0
    One more question...does the COUNTIFS function use these criteria as a "filter", per se, based on order of criteria? So, in this case, does the COUNTIFS function first filter the array to meet the first criteria (match the names), then count the number of entries with a date that occur earlier than the filtered entries? I guess I would just assume that the second criteria (count if there are no occurrences where the date is earlier) would only occur once in the entire array: the very earliest date for ALL employees; not once for every employee. Clearly I'm wrong in this assumption, but would someone mind explaining why this method can work??

    Thanks!

  12. #12
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Need to return the earliest date respective to one criteria

    COUNTIFS only counts rows where all conditions are met (two in this case) so when you use this formula

    =COUNTIFS(A:A,A2,B:B,"<"&B2)

    ....it is counting the number of rows where both conditions are fulfilled, i.e. column A matches the name on the current row and column B has a date earlier than the date on the current row. If the result of that formula is zero then that means there are no rows where the name is the same and the date is earlier........hence this row must have the earliest (or equal earliest) date for that name.

    The formula suggested by Fotis will give the same results if correctly entered

+ 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