"If" "then" Statements with Math.js in zzTakeoff!
Looking to learn more about advanced formulas with math.js in zzTakeoff
NUMERICAL IF THEN STATEMENTS
Let’s start with the basic explanation and practice and there are a couple ways to skin the cat. I like this style of expression as it helps be build better formulas.
For this I made a custom property [pipe size] which is a dropdown with 6,8 and 12” pipe sizes,
It starts like this:
· if- always small letters outside of any brackets. It starts off with an answer to your formula question. Your questions could be simple or abstract… what size of trench should I use for different pipe sizes? A vocal answer would be “if your pipe is 6 inches then use a 12” Trench, but if you pipe is 8 inches then use a 14” trench, or if your pipe is 12 inches then use an 18” trench.” Now let’s put that into a formula and it all starts with if…
· if( - be sure to use a parenthesis after if.
· if([pipe size] this is the zz Takeoff property that you have already built.. be sure and use the brackets.
· if([pipe size]== we use double equal signs in this case, but it could be >=, <= if that is what you are looking for.
· if([pipe size]==6 6 is our first option per the above question.
· if([pipe size]==6, the comma is basically the work then in our question above.
· if([pipe size]==6,12 the question above said that we need to use a 12inche wide trench.
· if([pipe size]==6,12, the next comma represents ELSE, so the number if it is NOT a [Pipe size] =6.
· if([pipe size]==6,12,0 the 0 is now the answer… if it is not 6” then return the number ZERO.
· if([pipe size]==6,12,0) Complete this expression with a parentheses
Now you are probably wondering what about the rest? You can now chain these formulas together to answer the rest of the questions by adding a plus sign in between them. Be sure to put the right answers and pipe sizes.
if([pipe size]==6,12,0)+ if([pipe size]==8,14,0)+if([pipe size]==12,18,0)
By doing this it will add the right answers to the wrong answers. If we have a [pipe size] of 12, then as the formula runs through it will add 0,for the 6, 0 for the 8 and 18 for the 12” pipe. So the answer will be 0+0+18. ……or 18
OR(||) AND (&&)statements
if([pipe size]==6,12,0)|| if([pipe size]==8,14,0)||if([pipe size]==12,18,0)
This will return as true if any of the values were selected
if([pipe size]==6,12,0)&& if([pipe size]==8,14,0)&&if([pipe size]==12,18,0)
This will return false unless all of the pipes were selected
This formula is if you want to choose a number in a range. In this case if the depth is greater or equal to 1.1 and less than or equal to 1.5, if this is the case then it will multiply by 2
((if([Depth]>=1.1,1,0)&& if([Depth]<=1.5,1,0))* 2) * [Linear:FT]
Updated on: 29/04/2026
Thank you!