+ Reply to Thread
Results 1 to 9 of 9

find which row best matches the criteria

  1. #1
    Registered User
    Join Date
    09-02-2010
    Location
    PHILIPPINES
    MS-Off Ver
    Excel 2003
    Posts
    3

    Smile find which row best matches the criteria

    Hi!

    I have a situation where I need to know which row among sixty rows best matches my target row. The rows contain strings as in the example below...



    Item1 Item2 Item3 Item4
    Row1 A B C D
    Row2 B B A C
    Row3 A C B B
    Row4 A B C A

    Row 1 (target row) is most similar to row4 since three of the items are similar in both rows. I tried using many helper cell to execute all iterations but this proved to be too cumbersome. Is there a way I can have a cell return row best match a target row. Note that all rows are possible target for comparison.

    Thanks in advance,

    Smokey

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

    Re: find which row best matches the criteria

    What is more similliar compared to ABCD:

    ABBB which have first two on right positions
    or
    DCBA which don't have right position but have all 4 values
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    09-02-2010
    Location
    PHILIPPINES
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: find which row best matches the criteria

    Zbor,

    Sorry for the late reply, --weekend got me a little tied up.

    ABBB is more similar. Like an answer key, a target row is compared for every item with each--say 100 rows in the range. Only in an answer key, you only compare one row after that you're done. My problem is after comparing one row, I move to the next row and compare it with the rest of the 100 rows in the range, and so on until I'm done with all of the rows in the range.

    I tried achieving it through many helper cell using a lot if IF statements, even creating a table of matrix to prevent duplicate comparisons. I'm sure there is a better way of doing this but right now, I'm really stumped because some other solution I can think of is just as cumbersome.

    Thanks for the help.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: find which row best matches the criteria

    You can add this into next column (row 2,3,4 etc): =SUMPRODUCT(--(B$2:E$2=B3:E3)) and pull down...

    You can also by index match pull out row that matching criteria or you can higlight them as in eample.
    Attached Files Attached Files

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

    Re: find which row best matches the criteria

    Donkeyote, can I ask you here how to make SUMPRODUCT work in this case...

    This is idea: =SUMPRODUCT(--(A$1:D$1=A2:D17);ROW(A1:D17)) (to comibe all rows somehow)...

    OK.. So I would like to see all rows from 2 to 17 and multiply first row by 1, second by 2 etc... Obviously here is only 17 rows (no matter on A1:D17... it's same as A1:A17)... But if I put A1:A64 it also doesn't work because first part looks like (Evaluating formula) ie:
    0\1\1\0;1\1\1\1:0\1\0\1; etc.

    In other words it's separated in quarters.. So I would like to know what's syntax in that case

    Even if it can be solved in another way I would like to see how to make it work somehow

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: find which row best matches the criteria

    zbor - as much as I am flattered by the personal request I must confess I don't really understand the requirements.

    Are you saying you want to multiply the n match results of A1:D1=A2:Dn by 1 to n-1 ?
    (note you have 16 match results rather than 17)

    eg:

    A1: A A C D
    A2:...
    A3: A B C D
    For the iteration of row 3 I presume you are looking to return 6 (1*2, 0*2, 1*2, 1*2), correct ?

    If so - given the dimension differences of the arrays (ie n x 4 vs n x 1) use * rather than double unary.
    given there's no potential for invalid coercion there's little reason to avoid multiplication (ie we're just multiplying booleans & integers)

    Please Login or Register  to view this content.
    Does that help ?

    If you wanted to avoid need for multiplication (ie persist with double unary) then to get the 2nd array to also conform to n x 4 dimension there are a few possibilities, eg:

    Please Login or Register  to view this content.

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

    Re: find which row best matches the criteria

    Regardless to the issue I just couldn't adjust ranges and I see it was because of double array... So I just wanted to see how it works... 'Cause I had some idea at the time and couldn't get it work But I see now it doesn't work anyway so no big deal about it

    Thx for the help, you helped a lot...

    Oh, yes, just for a feedback idea was to give 1's for matches in first row, 2's for second etc...

    =SUMPRODUCT(($B$2:$F$2=$B$3:$F$18)*(ROW($A$1:$D$16)))

    But I'm giving up now.. Waiting to see if user is satisfied with answer or need some improvements

    Thx again!

  8. #8
    Registered User
    Join Date
    09-02-2010
    Location
    PHILIPPINES
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: find which row best matches the criteria

    Bless you sirs! I am right now replacing my million helper cells with your suggestions. ..will feedback as soon as I get something right.

    Many thanks!



    Quote Originally Posted by zbor View Post
    Regardless to the issue I just couldn't adjust ranges and I see it was because of double array... So I just wanted to see how it works... 'Cause I had some idea at the time and couldn't get it work But I see now it doesn't work anyway so no big deal about it .....


    ....Thx again!

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: find which row best matches the criteria

    Lightweight helper cells are no bad thing - a multitude of SUMPRODUCTs on the other hand...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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