HomeFormulas

# Creating formulas

Formulas let you work with numbers, ranges, and other variables. Here are some examples:

• `25` : constant value of 25
• `1 to 5` : range from 1 to 5 (technical detail: symmetric triangle distribution)
• `(0 to 1) * MyVariable` : the product of a range and another variable
• `if VariableA > 10 then 1 else 0`: self explanatory. You can link multiple conditions with `and` and/or `or`. See if statements for more!
• `sample(3, 5)`: either the value 3 or the value 5 (discrete distribution)

You can preview the formula in the top bar, and if you hit enter/F2, you can edit/set the formula.

The formula column (if toggled on in the toolbar) sets the formula for all timesteps by default. If you want to set a different formula/value for a particular timestep, just go to that timestep's column and edit/set the formula there. If you have an existing variable whose formula/value varies over time, you can use the Formula column to override the formula/value for all timesteps in one go.

### The Basics

• The syntax for basic operations is the same as Excel: `+ - * / ^ > < =`
• Not equal to is either `<>` or `!=`
• You can reference variables in formulas by typing the variable name and selecting it from the autocomplete dropdown. You can also reference variables in other models if they're linked.

• You can add comments to your formulas with a double slash `//` Everything between the double slash and the end of the line will be ignored by Causal when calculating. This is useful when you want to remind yourself (or others) what the formula is doing.