+ Reply to Thread
Results 1 to 6 of 6

Count Values which Co-Occur with one another

  1. #1
    Registered User
    Join Date
    01-18-2019
    Location
    Durham, New Hampshire
    MS-Off Ver
    2016
    Posts
    1

    Count Values which Co-Occur with one another

    I am the director for a nonprofit, volunteer ambulance with about 60 volunteers. I am trying to develop a way to see which pairs of volunteers work together the most (respond to the most calls together).

    My data is formatted as follows:

    Column 1: Run Number (unique to each call)
    Column 2: Volunteer Name

    The run number is repeated in a new row for every volunteer on the call Put another way, my data set has a row for each unique combination of runs / volunteers (5000+ rows). So it looks something like this:

    18-11111 John Doe
    18-11111 Mary Jane
    18-11111 George McGregor
    18-22222 Mary Joe
    18-22222 John Smith
    18-33333 John Doe
    18-33333 George McGregor

    My goal is to have something that would show me (in this example) that John Doe & George McGregor responded to two calls together. I have tried considering ways to do this via a Pivot Table or formula but cannot come up with anything.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Count Values which Co-Occur with one another

    Hi

    This is an interesting project for a good cause.

    I have solved this for you.

    I am in the process of making it bullet proof.

    Will be back shortly.


    Make sure row 1 is empty and your data starts in row 2

    Ok:

    Paste this formula in C2 and fill down =IF(AND(A2=A3,A3=A4),B2&": " &B4,IF(A2=A1,B1 & ": " &B2,""))

    Paste this formula in D2 and fill down =IF(OR(ISERROR(INDEX($C$2:$C$2000,MATCH(0,COUNTIF($D$1:D1,$C$2:$C$2000),0))),INDEX($C$2:$C$2000,MATCH(0,COUNTIF($D$1:D1,$C$2:$C$2000),0))=0),"",INDEX($C$2:$C$2000,MATCH(0,COUNTIF($D$1:D1,$C$2:$C$2000),0)))

    Activate this formula by selecting D2, Clicking into the formula box. Press and hold Ctrl, Press and hold shift, Press Enter and release all keys.

    Now Fill the formula in D2 down until you get empty rows.

    Paste this formula in E2 and fill down =COUNTIF($C$2:$C$200,D2)

    '*************************************************************************************************************************************************

    This Macro does all the work for you:

    I am adding explanations so you can maintain this yourself.

    I created the formulas in Excel and then recorded myself entering them into the cells using the Macro Editor.
    I then modified the recorded macro so that I could make the Last Row LR dynamic

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 01-18-2019 at 08:24 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Count Values which Co-Occur with one another

    Impressive. But in case of 4 rows with the same ID works incorrectly (I don't know if this case can appear).
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Count Values which Co-Occur with one another

    Thanks KOKOSEK

    I am waiting to see if that is possible.

    I guess the formula should not be impossible.

    There would be six combinations oo it might need another Column Though. Failing that a UDF.
    Last edited by mehmetcik; 01-18-2019 at 09:00 PM.

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Count Values which Co-Occur with one another

    Not sure how practical this would be with the real data, but it works.

    Run Numbers in A2:A8, Volounteer Names in B2:B8

    Pivot table started in E1
    Pivot columns:- Voloutnteer Name
    Pivot rows:- Run Number
    Pivot Values:- Count of Run Number

    Copy the Names from the pivot table (F2:J2) and paste to F10:J10
    Copy the names again, and Pastespecial > Transpose to E11:E15 so that you have names as row and column headings for a new table.

    Enter this formula into F11, then drag right and down to populate the table.

    @ mehmetcik, any thoughts for improvement?
    I'm wondering if it can be simplified in PQ but don't have a clue where to start with that.

  6. #6
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Count Values which Co-Occur with one another

    Here is a non-VBA attempt. Source data formatted per the OP's initial post is entered in blue-shaded columns A & B. This is the only necessary data entery - all other columns are calculated. All possible pair combinations are computed in column-J. The number of times each pair is present on the same call (the required answer) is computed in column-K.

    Notes:

    1) It is necessary to enter "zz" after the last call ID in column-A.

    2) It is assumed that the call-ID / participant data is sorted by Call-ID.

    3) Formulas have been copied down as far as necessary to support up to 60 participants/volunteeers. A maximum of 500 unique calls and an average of 3 volunteers per call has been assumed. If these limits are extended much further then Excel on my 6GB laptop becomes unstable.

    A brief explanation of helper columns C thru I:

    Column-C helps towards creating a consolidated list of participant names per call

    Column-D is a list of unique distinct call-IDs and column-E is the corresponding comma separated list of participant names.

    Column-F is a list of unique distinct participant names. Columns G & H list all possible pairs of names (if there are N names then there are N^2 pairs).

    Column-I eliminates pairs where the first name and second name of the pair are the same and puts pairs in alphabetic order so that John, Fred becomes Fred, John. Finally column J is column-I with duplicates eliminated to yield the n!/((n-2)!2! valid name pair combinations. Finally, column-K then computes how many times each of these pairs have been on the same call.

    See the attached workbook.
    Attached Files Attached Files

+ 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 doubles that occur ΑΤ ΤΗΕ SΑΜΕ ΤΙΜΕ
    By louis128 in forum Excel General
    Replies: 20
    Last Post: 12-31-2018, 03:26 AM
  2. Replies: 10
    Last Post: 10-09-2014, 08:06 PM
  3. [SOLVED] Count how often multiple number values occur by using functions
    By joefitness in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-29-2014, 12:21 AM
  4. Replies: 8
    Last Post: 07-14-2013, 07:29 PM
  5. [SOLVED] How to count values that occur in a single cell...Detailed explanation inside
    By Soulseeker in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-02-2013, 03:02 PM
  6. Replies: 2
    Last Post: 05-11-2010, 12:25 AM
  7. Count when values occur in different arrays
    By smileyc in forum Excel General
    Replies: 6
    Last Post: 02-26-2009, 07:56 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