However counterintuitive it sounds, I tend to go for longer syntax structures for visualizing - just my personal preference. As long as you get an accurate result, play with whatever syntax works for you. Of course, if a formula is rather complex, go for simplicity for the sake of space.
Basic Syntax for Calculations
Calculations work like algebraic expressions, whereby the order of commands must arrange in a hierarchy. For those unfamiliar with spreadsheets or haven't applied math in a while, writing down calculations as expressions first can help with transferring into a table formula. For example ...
Syntax for add, subtract, divide, multiply:
Syntax 1 โ 3 + 4 = 7
Syntax 2 โ add(1, 3) == 4
โ we want to add total revenue from 15% Discount sales to full-price sales then add Register Balance to return the amount in Register Close for the end of the day.
โ Math: a(b-d) + d(a-(a*.15)) + c = x
โ Notion Formula: multiply(prop("Price"), prop("Sold") - prop("15% Discounts")) + multiply(prop("15% Discounts"), prop("Price") - prop("Price") * .15) + prop("Register Balance")
Broken Down:
a(b-d) โ
multiply(prop("Price"), prop("Sold") - prop("15% Discounts"))
+ d(a-(a*.15)) โ
+ multiply(prop("15% Discounts"), prop("Price") - prop("Price") * .15)
+ c โ
+ prop("Register Balance")
Alternate Syntax
If you're having a hard time visualizing the above syntax, this one works too ...
โ Notion Formula: prop("Price") * (prop("Sold") - prop("15% Discounts")) + prop("15% Discounts") * (prop("Price") - (prop("Price") * .15)) + prop("Register Balance")
Broken Down:
a(b-d) โ
prop("Price") * (prop("Sold") - prop("15% Discounts"))
d(a-(a*.15)) โ
+ prop("15% Discounts") * (prop("Price") - (prop("Price") * .15))
c โ
+ prop("Register Balance")
What Commonly Breaks A Formula
Parenthesis:
Always check your parenthesis placement. Every open parenthesis "(" must be paired with a close parenthesis ")". Refer to algebraic formula for parenthesis placement. This usually helps.
Line of Logic:
Always check your line of logic. What is placed at the beginning of a formula doesn't always override what is placed below it. For example, if the first line reads checkbox if false and the second reads checkbox if true, it will check every box. Understand what you want as an outcome before diving in. This example is easy to fix, but on a larger scale, it can get annoying.
Misspellings:
When grabbing a property ... ie. prop("PROPERTY NAME"), make sure the spelling matches your property header and also keep in mind that it is cap sensitive. A lot of the time when I think my syntax or line of logic is incorrect, it's actually my property tag that's misspelled. Check these before assuming your formula is broken.
Other Common Mathematic Functions
return exponent power
Syntax 1 โ 5 ^ 3 == 125
Syntax 2 โ pow(2, 6) == 64
find length of string
length(text)
return number from text
This is useful for text that has a number value โ this number value can be used in calculations if toNumber is placed before it.
toNumber(text)
toNumber(number)
toNumber(boolean)
toNumber(date)