+ Reply to Thread
Results 1 to 8 of 8

Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

  1. #1
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,636

    Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    I wonder if anyone can advise? I am trying to create the following clashing grid to count the number of times two items appear together on the same row.

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    1
    Apples Bananas Cherries Damsons Elderberries
    2
    Apples
    4
    4
    Apples Bananas Elderberries
    3
    Bananas
    4
    4
    Bananas Apples Cherries
    4
    Cherries
    3
    Elderberries Cherries Damsons
    5
    Damsons
    2
    Damsons Bananas Apples
    6
    Elderberries
    2
    Apples Cherries Bananas
    Sheet: Sheet1

    The table on the right has rows of choices: no choice can be repeated on any row, so each row will have three unique entries. In the clashing grid on the left I need to show the total of times paired items appear at their intersection point on the clashing grid. Here apples and bananas appear together in a row four times, so the number 4 should appear at their intersection on the clashing grid. What would be the formula for cell B3, please?
    Attached Files Attached Files
    Last edited by AliGW; 03-06-2017 at 01:55 PM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,660

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    Try this in B2 (CSE):

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And drag to other cells.
    Last edited by zbor; 03-06-2017 at 08:41 AM.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    Hi Ali,

    This looks a lot like a problem I had a few years ago. I wanted to know how many times people were playing golf in the same threesome (on the same row). See if this formula doesn't make your heart stop. In B2 and then pull and drag..

    =SUMPRODUCT((MMULT(($I$2:$K$6=B$1)+($I$2:$K$6=$A2),{1;1;1})=2)+0)

    If you really need the zeros then do this in B2

    =IF(SUMPRODUCT((MMULT(($I$2:$K$6=B$1)+($I$2:$K$6=$A2),{1;1;1})>=2)+0)>1,SUMPRODUCT((MMULT(($I$2:$K$6=B$1)+($I$2:$K$6=$A2),{1;1;1})>=2)+0),0)

    Clashes Grid for Ali.xlsx

    Note = if you had 4 columns then make the {1;1;1} a {1;1;1;1}.

    I need to give credit to either DaddyLongLegs or 6StringJazzer for my answer above. I worked on my problem for hours and it gave me a huge headache. It took me a few hours of study to see why it worked.
    Last edited by MarvinP; 03-06-2017 at 08:49 AM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    If your values can only appear once in each row, you don't actually require the >0 part of zbor's formula. I came up with
    =SUM(COUNTIF(OFFSET($I$2:$K$6,ROW($I$2:$K$6)-ROW($I$2:$K$2),0,1),B$1)*COUNTIF(OFFSET($I$2:$K$6,ROW($I$2:$K$6)-ROW($I$2:$K$2),0,1),$A3))
    though I must say I do like Marvin's answer better!
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,660

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    Quote Originally Posted by xlnitwit View Post
    If your values can only appear once in each row, you don't actually require the >0 part of zbor's formula. I came up with
    =SUM(COUNTIF(OFFSET($I$2:$K$6,ROW($I$2:$K$6)-ROW($I$2:$K$2),0,1),B$1)*COUNTIF(OFFSET($I$2:$K$6,ROW($I$2:$K$6)-ROW($I$2:$K$2),0,1),$A3))
    though I must say I do like Marvin's answer better!
    Yes. >0 is to avoid Apples Bananas Apples to be counted twice.
    I also agree that Marvin's is much elegant

    But now it need to consider what to do in case of multiple appearance, if can happen' because mine and Marvin's will return different result.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    The original post stipulated that "no choice can be repeated on any row, so each row will have three unique entries"

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,660

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    Then we have a winner

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,636

    Re: Creating a Clashing Grid - COUNTIFS and/or SUMPRODUCT Array Formula?

    Thank you ALL very much! Marvin's elegant and quite short solution is the one I'm going with. I knew one of you would work it out.

+ 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] Possibly looking for a SUMPRODUCT alternative to a current IF(COUNTIFS( formula
    By Twaddy006 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-16-2015, 02:40 PM
  2. [SOLVED] I need COUNTIFS or SUMPRODUCT formula to count ONLY Non-Consecutive values
    By justinbelkin in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-19-2013, 03:24 PM
  3. SUMPRODUCT and COUNTIFS formula that is returning #DIV/0!
    By caseyjones05 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-19-2013, 03:37 PM
  4. Trying to use the COUNTIFS formula, but might need SUMPRODUCT instead?
    By jeepjenn in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-25-2013, 12:02 PM
  5. Replies: 3
    Last Post: 01-20-2012, 01:20 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