Forum Discussion
"Close enough" MATCH
- Nov 15, 2018
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:
And what is in B7:B10? Even better if you attach the file with your sample
The "B7:B10" thingy -- I had copied the original spreadsheet down a few rows, so that I could mess with the formulae without changing the original version.
Using the "=MATCH(1,INDEX(--(ABS(A7-B7:B10)<=0.05),0,),0)" seems to be working. Most importantly, this formula does return a "N/A" if no match was found, because I need that "N/A" to catch when a statement doesn't match a deposit (I use conditional formatting to make that stand out bigly).
One final note: I think the "<=0.05" should probably be "<=0.005" (a half of a penny instead of a nickel. I'll make that change (actually, I'll create a "tolerance variable" and put in a cell, so that I can make changes on the fly.
I'll play with this a bit, including that alternate "MATCH' formula that was suggested. Then, I'll try to implement it in my big honkin' spreadsheet over the weekend. I'll report back.
Thanks to all for the help! I'll report back shortly.
- SergeiBaklanNov 16, 2018Diamond Contributor
Jon, when nothing is found instead of returning an error code #N/A it's better to wrap the formula by IFNA or IFERROR and return any text/value you prefer
=IFNA(MATCH(1,INDEX(--(ABS(A1-B1:B4)<=0.005),0,),0), "No such")
- Jon CohenNov 17, 2018Copper Contributor
I've spent some time today integrating the proposed solutions into my big honkin' spreadsheets, and it appears to be working well.
Of course, it drives me crazy that the grand total of the statements is $0.00000478 different from the deposits. I'm gonna have to pocket that $0.00000478, because I can't figure out how to pay that out.
Thanks for all your assistance, guys.
- SergeiBaklanNov 17, 2018Diamond Contributor
Jon, why don't you ROUND to cents your totals and intermediate results? Precision is always exists in calculations, even =1*(0.5-0.4-0.1) is not equal to zero in Excel.