Links

If statements

When you want a variable to have different values or formulas based on a condition, you can use if-statements. They always have to follow the structure if condition then X else Y
You can link multiple conditions with and and/or or:
  • if condition1 or condition2 then value1 else value2
  • if condition1 and condition2 then value1 else value2
You can also link conditions with a list, for example:
  • if month in [11, 12, 1, 2] then 90% else 100% -> means if the month is Nov, Dec, Jan or Feb, return 90% else return 100%.
  • You can also use categories / category items in if-statements, see Category Items in formulas for more.
You can have multiple layers of if statements too, for example:
  • if condition1 then value 1 else if condition2 then value2 else [...]
  • You can break each of these layers out onto separate lines of your formula editor using shift + enter
  • Note that every if statement must have an else, otherwise Causal will return an error.
Examples of if statements:
  • if timestep > 4 then 1 else 0
  • if variable1 > variable2 then 100 else 200
  • if timestep > 4 and timestep < 10 then 1 else 0
  • if variable1 < 10 then 100 else if variable1 < 20 then 200 else 300