Forum Discussion

Jon Cohen's avatar
Jon Cohen
Copper Contributor
Nov 14, 2018

"Close enough" MATCH

I run a business using a big honkin' complex Excel worksheet.  I've installed several checks to make sure I've entered data correctly.

 

I get a moderate number of reports from various sources, each containing a detailed statement that represents a revenue from a number of products.  I enter the amounts from the statements in one part of my spreadsheet (where the components are totaled up), and I enter the bank deposit amounts in another part.  One of my checks is to ensure that the grand totals entered from the statements MATCH one of the bank deposits.

 

For years, this worked well.  But recently, several of the sources have taken to tracking fractions of a penny.  So, a bank deposit of, say, $100 might match a statement that has a grand total of $99.9996 or $100.00004.  So, my "exact MATCH" formula returns a "N/A" when I would want this to return a MATCH. 

 

I realize that I can use MATCH to return the deposit number of the deposit that is closest to the statement, but to use this feature, I have to choose the match that is closest without going over or the match that is less but not equal to the match.  This is not what I want, because if I use this feature, I might match a statement to a deposit that has nothing to do with the statement at all. 

 

What I want is a "close" MATCH function that matches a statement to a deposit +/- $0.005 (or some value I can set).   I'm looking for a "close enough" MATCH.  How can I do that? 

 

Thanks in advance.

  • Jon, for better understanding how the formula works you may stay on the cell with formula (any one) and on ribbon Formulas->Evaluate Formula to see step by step what formula calculates.

     

    Alternatively in formula bar you may select part of the formula which performs this or that calculation, F9 to see result of it and Ctrl+Z to return back.

     

    As for you questions

    1) Yes, arithmetic operation of single value and array performs that operation on each element of the array. You may try =SUM({2,3}+2), it returns 9 and intermediate calculation is =SUM({4,5}). Check with evaluate. Thus yes, that part of the formula returns an array like

    {abs(a1-b1), abs(a1-b2)abs(a1-b3)abs(a1-b4)}

     

    2) Correct, that will be an array with TRUE and FALSE

     

    3) Double dash transform logical value to its numeric equivalent.

    =--TRUE returns 1 (as well as =TRUE*1 and =TRUE+0)

    =--FALSE returns 0, similar to above

     

    4) If you need position, not the value on that position, as Detlef mentioned just don't use outer INDEX

    =MATCH(1,INDEX(--(ABS(A1-B1:B4)<=0.05),0,),0)

    In addition, inner INDEX here allows to avoid using of array formula, it returns resulting after ABS calculations array directly to MATCH. Alternatively you may use array formula (Ctrl+Shift+Enter)

    =MATCH(1,--(ABS(A1-B1:B4)<=0.05),0)

    which returns the same result:

    • Jon Cohen's avatar
      Jon Cohen
      Copper Contributor

      Thanks.  The good news -- your solution appears to work.  The bad news -- I don't fully understand your solution.  Here are my questions:

      • ABS(A1-B1:B4) -- I don't know what this construction, where an array (B1:B4) is subtracted from a single cell.  Does this return an array, where each element of the array is the original array's value subtracted from the value in A1.
      • (ABS(A1-B1:B4)<=0.05) -- Again, I don't know this construction, but since I'm presuming that the ABS function is returning an array, the "<=0.05" part then creates an array full of TRUE or FALSE values, depending on whether the values in B1:B4 are within 0.05 of the value in A1.
      • --(ABS(A1-B1:B4)<=0.05) -- I don't know what the "--" means.  What does it mean?
      • Okay -- all I'm looking for the is position in the array of the matching "close enough" value.  Thus, instead of returning "10.0005", I want it to return "3", as in the third element in the array where the "close enough" match is found.

      So, thank you, but can I get a little more help?

Resources