Here are a few further notes relating to the questions raised above...
First off, contrary to what I said previously, tests on various formulas in the attachment indicate there is
no significant difference with using CSE on formulas and that multi-cell array formulas can be fastest for returning a set of values from a list (tested with Office 2016 64 Bit.)
• what's the role of the Tilde sign before the "x"? .. "x" is not a wild card, is it? .. I removed the tilde and the result becomes 1
The INDEX/MATCH functions are each executed twice inside the formula, once with match_type = 0 and once with match_type = -1. These two cases treat the tilde differently.
match_type=0. The tilde is just an escape character for wildcards (*,? and ~) it has no effect on other characters. So in this case "~x" = "x" and the first match is returned.
match_type=-1. The tilde is matched according to the descending sort order. Since "~x" < "x", the last match is returned.
• I don't understand how the MATCH Function returns an array? and how it deals with the IF result. As a matter of fact, if I change the IF block with the result {0,-1} - (Actually, it is always equal to {0,-1}) - then I get 1 as the final result of the whole formula ... why?
One way to find out the types of input / output of the MATCH and IF functions is:
1. Open the function wizard to show the basic input types: value (number, logical, text, any), reference or array...
=MATCH(any,number,number)
=IF(logical,any,any)
2. Enter a {1} for each input in the function wizard and check what is displayed next to the input box to see if array is an input/output type...
=MATCH({1},{1},{1}) -> MATCH(1,{1},1) =1
=IF({1},{1},{1}) -> IF({1},{1},{1}) ={1}
3. Enter A1 in each input and then step through with the evaluate tool to see if references get converted to values, if not then input/output is a reference type...
=SUM(MATCH(A1,A1,A1)) -> SUM(MATCH(1,A1,A1)) -> SUM(1)
=SUM(IF(A1,A1,A1)) -> SUM(IF(1,A1,A1)) -> SUM($A$1)
I find applying formatting for
value,
reference,
array can help visualise things:
MATCH ( lookup_value,
lookup_array,
match_type )
IF (
logical_test,
value_if_true,
value_if_false )
Passing the
IF result to the
match_type argument forces an array return. It turns out this combination of
Array+
Reference output together with the
Value+
Reference input can be applied to return an array in general. (A complete list of functions with types was recently posted in the vault forum for reference.)
In effect, the array is being passed
by reference in the match_type argument when IF(1,{0,-1}) is inserted as opposed to
by value when just {0,-1} is used
.
• Can the INDEX Function return an array?
Yes, INDEX can return an array when the second or third argument is zero. The reference form of INDEX (in the notation above) is:
INDEX (
reference, row_num, column_num, area_num )
Because INDEX can return arrays it does not process arrays within value arguments. (According to OpenFormula documentation "Functions returning arrays are not eligible for implicit iteration").
So it seems any of the value inputs (row_num, column_num or area_num) need to be coerced to an array using a method similar to the MATCH+IF combination.