The CHOOSE function evaluates the first argument, which in your example
is...
(B9="X")+2*(C9="Y")+1
in order to get an index number (1, 2, 3, etc.). Whatever the index value
evaluates to, that item number in the list that follows is retrieved. So,
for you example, if the above expression evaluates to 1, the text string
"neither" is returned; if it evaluates to 2, the number 5 is returned; if it
evaluates to 3, 6 is returned; and if it evaluates to 4, the text string
"both" is returned. Now, let's look at how the above expression is
evaluated. Both ((B9="X") and (C9="Y") are what are called "logical
expressions"... they will either evaluate to TRUE or FALSE. When used in a
mathematical expression, Excel treats TRUE as the number 1 and FALSE as the
number 0. So, if B9 is not "X", it will evaluate to 0 and if it does equal
"X", it will evaluate to 1, in the mathematical expression. The same with
the second logical expression... if C9 does not equal "Y", it evaluates to 0
and if it does equal "Y", it evaluates to 1. The 2* part makes sure that the
two logical expressions do not make the mathematical expression evaluate to
the same non-zero index number. That is, (B9="X") will contribute only 0 or
1 in the mathematical expression, 2*(C9="Y") will only contribute 0 or 2 to
the expression. Therefore, the four possible results are 0,1,2 or 3
depending on how the logical expressions evaluate. However, the CHOOSE
function requires its index values start number at 1, so the mathematical
expression add 1 to the result to bump the 0,1,2 or 3 return values to 1,2,3
or 4 and that value is used to retrieve the items from the return list part
of the CHOOSE function.
Rick