+ Reply to Thread
Results 1 to 10 of 10

How to identify pairings and repeats in population data

  1. #1
    Registered User
    Join Date
    09-06-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Office:Mac
    Posts
    5

    How to identify pairings and repeats in population data

    Hi guys

    I have a problem that I hope someone can help me to solve.

    I have a spreadsheet containing the ID numbers of over 6000 individuals within a population and the years in which they bred. My task is to input the breeding pair for each bird and assign a unique ID number to each 'pair' of birds.

    I have attached a completed example to this post.

    To simplify things, if we imagine that it's human population data of married couples within a town where:

    Column A represents ALL individuals
    Column B represents the year of the census
    Column C represents the spouse of the individual in column A
    Column D is a unique assigned ID number for that 'couple'

    As column A is made up of ALL individuals and almost all couples appear in more that one census, I'm looking for a way to simplify my data input.

    As I enter data into column C, I want that 'couple's' data to be copied into the corresponding cells for that couple further down the spreadsheet where the spouse of that couple is listed, providing the year is correct of course.

    Example:

    As I enter the ID into cell C8 and D8, the data from A8 and D8 are entered into cells C9 and D9 respectively as the year in B8 and B9 are identical.

    It is important that only the pairs in the correct years are copied. If you look at line 12, one of the individuals from a previous pair have a different partner and therefore a new unique pair_ID has been created.

    Is that something that's possible?
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to identify pairings and repeats in population data

    Put this formula in D2, then copy down:
    =IFERROR(INDEX($D$1:$D1, MATCH(A2&"-"&C2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0)), MAX($D$1:$D1)+1)


    To remove the formulas
    1) highlight the entire column D
    2) Copy
    3) Paste Special > Values
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-06-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Office:Mac
    Posts
    5

    Re: How to identify pairings and repeats in population data

    Thanks for your reply, but that's not quite working as I'd hoped.

    Line 5 and 6 are identical pairs to lines 2 and 3 but the other way round (BA rather than AB). Your formula has mistaken it for a different pair and created another pair_ID.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to identify pairings and repeats in population data

    Try this:

    =IFERROR(IFERROR(INDEX($D$1:$D1, MATCH(A2&"-"&C2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0)), INDEX($D$1:$D1, MATCH(C2&"-"&A2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0))), MAX($D$1:$D1)+1)

  5. #5
    Registered User
    Join Date
    09-06-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Office:Mac
    Posts
    5

    Re: How to identify pairings and repeats in population data

    Thanks very much for your help. This assigns the a unique pair_ID perfectly.

    Is there any way for the formula to also identify the pair further down the spreadsheet to save me having to add everything twice when a line contains the identical ID numbers for both birds and the same year?

    For example, imagine columns C and D have no contents and I enter 'EF70113' into cell C2. I would like the formula to search all of column A for 'EF70113' and assuming column B contains '1977' as per line 2, it enters 'ED81312' into column C and also copies the pair_ID of '1' into column D for that corresponding line.

    Essentially, as I complete line 2 in the example, line 5 will be completed also.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to identify pairings and repeats in population data

    Eeek, let me think about that.

    I don't really understand that. The formula give so far does nothing with the year. It looks for pairs of bird IDs and gives them an ID.

    Also, once that pair exists in the DB the first time, they get an ID, period. So further down the list will detect that ID and reuse it, so I don't really see what new thing you're adding here.
    Last edited by JBeaucaire; 09-07-2014 at 12:31 PM.

  7. #7
    Registered User
    Join Date
    09-06-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Office:Mac
    Posts
    5

    Re: How to identify pairings and repeats in population data

    Sorry, maybe I'm just not explaining myself very well.

    Within the spreadsheet, every 'pair' will appear twice for the year that they were together. Once in column A and again in column C once I've entered it.

    To prevent me from entering data into column C 6000 times, is there a way for the spreadsheet to detect that the number that I've entered into column C also appears further on in column A and providing the year is the same, automatically copies the ID of its partner for that year.

    Back to my initial 'human' population census as an example, let's suggest that the individual in cell A2 is Mr Jones, and in 1977 he lived with Mrs Jones and , thanks to your formula, a unique ID is created for 'Mr and Mrs Jones'.

    Further down the spreadsheet, Mrs Jones will be listed in column A under 1977 also. Is there a way for a formula to realise that Mrs Jones , in 1977, was living with Mr Jones (as in line 2) and automatically complete the cells in column C with Mr Jones and therefore completing the unique ID for 'Mr and Mrs Jones' as in cell D2?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to identify pairings and repeats in population data

    Assuming you were starting a NEW list with no data entered yet, then you can put formulas in column C to start with, formulas you would overwrite with a manual entry when you wanted.

    C2: =IF(OR(LEN(A2)<1, LEN(B2)<1), "", IFERROR(IFERROR(INDEX($C$1:$C1,MATCH($A2&"-"&$B2,INDEX($A$1:$A1&"-"&$B$1:B1,0),0)), INDEX($A$1:$A1,MATCH($A2&"-"&$B2,INDEX($C$1:$C1&"-"&$B$1:B1,0),0))), ""))

    D2: =IF(LEN(C2)<1, "", IFERROR(IFERROR(INDEX($D$1:$D1, MATCH(A2&"-"&C2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0)), INDEX($D$1:$D1, MATCH(C2&"-"&A2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0))), MAX($D$1:$D1)+1))


    Any better?

  9. #9
    Registered User
    Join Date
    09-06-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Office:Mac
    Posts
    5

    Re: How to identify pairings and repeats in population data

    That is fantastic. Thank you for saving me so much time.

    I really appreciate it

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to identify pairings and repeats in population data

    As it appears you've reached a conclusion, I've marked this thread SOLVED for you.
    FYI, this is done through the Thread Tools located above the first post in this thread. Thanks.

+ 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: 12-09-2012, 09:00 PM
  2. Replies: 0
    Last Post: 07-10-2012, 08:37 AM
  3. Formulae for: 4 most repeats,4 least repeats in a series of numbers
    By Sedge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2010, 04:56 AM
  4. Replies: 3
    Last Post: 07-04-2008, 07:42 PM
  5. Repeats of data
    By rdubya in forum Excel General
    Replies: 1
    Last Post: 09-16-2007, 10:02 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