Using Variables in Formulas
After you add a variable, you can use it in formulas for various system objects (columns, tables, views, etc.). It is important to remember that all variable values are treated by the system as a simple text. Therefore, you cannot simply input variables into formulas that deal with numbers or dates.
When creating formulas with a variable, you will need to convert the variable into a corresponding format. Variables are inserted into formulas in square brackets (for example, Var[hourly rate]
). To covert a variable into the necessary format, use the Type Conversion
functions ToXXX(Var[variable])
, for example:
-
ToNumber()
used to convert a variable to the number format (for example,ToNumber(Var[hourly rate])
); -
ToDate()
used to convert a variable to the date format (for example,ToDate(Var[beginning date])
); -
ToTimeOfDay()
function used to convert a variable to the day time format (for example,ToTimeOfDay(Var[day time])
).
When you create a formula, there may occur a situation when a variable and a column have the same name. References to column values and variables are given in formulas in the same way - in square brackets (for example,
Var[project start date]
). If the names of the column and the variable coincide, the formula will use the column value.
The following table contains examples of converting variables into a different format and using variables in formulas:
Variable Name | Value | Format to Convert to | Conversion Function | Formula Example, |
---|---|---|---|---|
hourly rate | 15.00 | Numeric | ToNumber(Var[hourly rate]) | oNumber(Var[hourly rate]*8) |
start date | 01-01-2006 | Date | ToDate(Var[start date]) | Today () - ToDate(Var[start date]) |