Forum Discussion

Immortalis's avatar
Immortalis
Brass Contributor
Feb 05, 2024
Solved

Compare arrays, find value that doesn't exist.

 

I have an array with 3 columns and another array with 4 columns. I'm trying to find a formula that will

compare the 3 values in a row in the 1st array, compare it to three values in a row in the 2nd array, find the first result that DOESN'T match an return the 4th value of that row from the 2nd array. (if that makes any sense).

 

Any help would be VERY appreciated.

  • Rodrigo_'s avatar
    Rodrigo_
    Feb 05, 2024

    Immortalis 
    it worked for me. I've just slightly revised the formula.

     

    =INDEX(H2:H4, MATCH(TRUE, MMULT(--(A2:C4<>E2:G4), TRANSPOSE(COLUMN(A2:C4)^0))>0, 0))

     

    note: this formula will only return the first mismatched from your arrays. and if you have multiple mismatches, it will need a SMALL function with ROW function as the second argument to the Nth smallest value from your arrays row numbers where there is a mismatch.
    formula if multiple mismatches:

    =IFERROR(INDEX($H$2:$H$4, SMALL(IF(MMULT(--($A$2:$C$4<>$E$2:$G$4), TRANSPOSE(COLUMN($A$2:$C$4)^0))>0, ROW($A$2:$A$4)-ROW($A$2)+1), ROW(A1))), "")

     after pasting that formula (with Ctrl+Shift+Enter) example in cell B9, then copy that cell and paste it in cell B10 and B11

  • sarahwilliam9o0's avatar
    sarahwilliam9o0
    Copper Contributor
    To compare arrays and find the value that doesn't exist, you can use the `INDEX` and `MATCH` functions in Excel. Here's a formula you can use:

    ```excel
    =INDEX(Array2[FourthColumn], MATCH(1, (Array1[Column1]=Array2[Column1])*(Array1[Column2]=Array2[Column2])*(Array1[Column3]=Array2[Column3]), 0))
    ```

    Replace `Array1` and `Array2` with the actual ranges of your arrays, and `Column1`, `Column2`, `Column3`, and `FourthColumn` with the appropriate column headers.

    This formula will compare each row of the first array with each row of the second array, and return the value from the fourth column of the first mismatched row found in the second array.
    • Immortalis's avatar
      Immortalis
      Brass Contributor
      But it needs to work within the 2nd array. So like, cell C45. The formula checks an array for a value matching criteria and then puts the value in C45 but before doing so, checks the C column first to see if that value already exists in the column. How do I get around the circular reference error?
  • Rodrigo_'s avatar
    Rodrigo_
    Steel Contributor

    Immortalis 

    Let's say your first array is in the range A2:C4 and the second array is in the range E2:H4.

    In the cell where you want to get the result, enter the following array formula: 

    =INDEX(H2:H4, MATCH(0, MMULT(--(A2:C4<>E2:G4), TRANSPOSE(COLUMN(A2:C4)^0)), 0))​

    This formula should works by comparing each row in the first array with the corresponding row in the second array. The MMULT() is used to sum the results of the comparison for each row. then MATCH() is used to find the first row where the sum is not zero (indicating a mismatch).

    • Immortalis's avatar
      Immortalis
      Brass Contributor
      I tried it out in my workbook and it came back with #VALUE!
      • Rodrigo_'s avatar
        Rodrigo_
        Steel Contributor
        it's an array formula, so rather than pressing Enter, you should Ctrl+Shift+Enter to input it.

Resources