Why does the AND() condition/function doesn't work with ArrayFomula

萝らか妹 提交于 2021-01-28 07:41:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!