Hi everyone,
I just realized the precedence rule for AND OR is totally wrong. Am I crazy??
Considering AND as a multiplier and OR as an adder (according to logic gates theory), the following should give me 4 rows as a result, without the need to add parenthesis.
Best,
Fernando Vizcaino
In order not to go crazy with AND/OR conditions, always put them in parenthesis in a logical way. 😁
It's good practice for whatever language you're writing in.
Hey @FilipR ,
I agree with you that it's a good practice, but that doesn't correct the issue.
It would be similar to having the following:
2+2x2 = 8
2+(2x2) = 6
As math principles are, logic gates principles should also be consistent here.
Best,
Fernando Vizcaino
🤣 I have never thought about it. But after checking I think your right @fmvizcaino !
Does the Formula Tool have a specific programming language or is it an Alteryx creation which is transpiled to a language?
@fmvizcaino C based but what ever converts it to C ignores precedence. Seems this has been hiding in plain sight 😅 great spot.
This is defeinetely an interesting use case @fmvizcaino 😀
Just ran into this issue myself... also had the same thought: what is going on, am I crazy here?? since it's such a basic principle of logical operators. Apparently it hasn't been corrected yet, so excessive parenthesis it is :)
Just seeing this --- but not sure what the issue is --- let's look at this in Node.js--
Use the boolean/logical OR operator (||) instead of the bitwise OR (|) in your js and you will get the "correct" answer of 4 items (last item in the array should be double mountain per the original post).
The tooltip for the formula syntax specifies that within the alteryx formula tool, the boolean operators are "||" "OR", which should not be applied consecutively but should instead respect precedence as others above noted (AND takes precedence, i.e. is executed first, before OR). This would be analogous to boolean/logical operators in other languages: SQL (AND/OR), Python (and/or), JavaScript (&&/||), etc.
Here's a simple example of the incorrect result being returned within the Formula Tool in test 1, fixed (which shouldn't be necessary) with parenthesis in test 2: