问题
AND
function: If I remove the Arrayformula() it works fine but It doesn't work with Array Formula.
Can I know the reason for it?
=ARRAYFORMULA(IF(ISNUMBER(G3:G),IF(AND( G3:G>=7.5,G3:G<=8),"Full Day",IF(AND(G3:G>8,G3:G<24) ,"Full Day+",IF(AND(G3<7.5,G3>=4),"Half Day",IF(G3<4,"Short Leave",)))),))
回答1:
As mentioned in my comment
Since you use the ARRAYFORMULA function you should use * instead of the AND function
=ARRAYFORMULA(IF(ISNUMBER(A3:A),IF((A3:A>=7.5)*(A3:A<=8),"Full Day",IF((A3:A>8)*(A3:A<24) ,"Full Day+",IF((A3<7.5)*(A3>=4),"Half Day",IF(A3<4,"Short Leave",)))),))
When using the ARRAYFORMULA
function you should use *
instead of the AND
function and +
instead of the OR
function.
Explanation
I don't recall an official site about this right now. In any case.
Point 1
Within an arrayformula, AND
gives a single value. Not an array of TRUE/FALSE
.
Point 2
You must also remember that in "math language", TRUE=1
and FALSE=0
Meaning
+----------+--------+
| Formula | Result |
+----------+--------+
| =TRUE+2 | 3 |
| =FALSE+2 | 2 |
+----------+--------+
As you can see one can interchange between boolean TRUE/FALSE
and 1/0
numbers.
Point 3
About the AND function
The AND function returns true if all the provided arguments are logically true and false if any of the provided arguments are logically false.
Putting it all together
In an arrayformula, instead of using AND/OR
when making comparisons, we take advantage of the above information.
So, the "multiplication" (A3:A>=7.5)*(A3:A<=8)
will return 1 (meaning TRUE
) only if both sides return TRUE
. All other conditions return 0 (meaning FALSE
).
This is the exact behaviour of the AND
function and does work in an ARRAYFORMULA
.
About the OR function
The
OR
function returns true if any of the provided arguments are logically true and false if all of the provided arguments are logically false.
The same logic is applied within the arrayformula, when using +
("addition") instead of the OR
function.
来源:https://stackoverflow.com/questions/64425099/why-does-the-and-condition-function-doesnt-work-with-arrayfomula