Formula Functions
Formula Functions
A formula computes a value: the outcome of a decision table rule, and with it the population of a derivable fact type. Formulas use the function names and the meaning you know from a spreadsheet (Excel, LibreOffice), so DATEDIF([Birth Date], [Pick Up Date], "Y") gives the same answer in CaseTalk as in a spreadsheet.
Writing a formula
A formula starts with =. It is typed in an outcome cell of a decision table rule (Edit OTFT > Decision Table tab > Rules).
- A column is written in brackets, with its header exactly as the decision table shows it: = [Return Date] - [Pick Up Date]. When two columns have the same header, name it by its path - in full or by its last steps, as long as only one column ends that way: [Pick Up Branch\Branch\Branch Code]. Upper and lower case do not matter.
- Arguments are separated by commas: = MAX([Base Rate], 10).
- Text is written in double quotes: = IF([Age] < 21, "young", "adult").
- A date counts as its day number, so subtracting two dates gives the number of days between them: = [Return Date] - [Pick Up Date] is the length of a rental in days. A function that returns a date (TODAY(), DATE, EDATE) shows it as yyyy-mm-dd, the way population stores dates.
- When a function cannot work with its arguments - DATEDIF with the start after the end, a text where a date is expected - the formula reports the error, as a spreadsheet does, and the rule gives no outcome for that example.
A formula computes; a condition only compares. A condition cell may compare with another column (>= [Return Date], see Cells), but it does not calculate. When a rule needs a computed value - an age, a duration, a number of days - let a derivable fact type compute it and let the rule read that fact.
Functions
Dates
| Function | Result | Example |
|---|---|---|
| TODAY() | today's date | DATEDIF([Purchase Date], TODAY(), "Y") - the age of a car in years |
| DATE(year, month, day) | a date; a month or day beyond its range rolls over | DATE(2026, 2, 29) = 2026-03-01 |
| YEAR(date), MONTH(date), DAY(date) | the part of a date | YEAR([Pick Up Date]) |
| DATEDIF(start, end, unit) | the time between two dates in complete units: "Y" years, "M" months, "D" days, "YM" months without the years, "MD" days without months and years, "YD" days without the years. The start may not be after the end. | DATEDIF([Birth Date], [Pick Up Date], "Y") - the age on the pick-up date |
| YEARFRAC(start, end [, basis]) | the fraction of a year between two dates; basis 0 (US 30/360, default), 2 (actual/360), 3 (actual/365), 4 (European 30/360) | YEARFRAC([Start Date], [End Date], 3) |
| EDATE(date, months) | the date the given number of months later (or earlier, when negative) | EDATE([Purchase Date], 12) - one year after purchase |
Logic
| Function | Result | Example |
|---|---|---|
| IF(condition, then [, else]) | then when the condition holds, else else | IF([Age] < 21, "young", "adult") |
| AND, OR, NOT, XOR | combine conditions | |
| = <> < > <= >= | compare | [Return Date] >= [Pick Up Date] |
Numbers
| Function | Result |
|---|---|
| + - * / ^ % | add, subtract, multiply, divide, power, remainder |
| ROUND(x), TRUNC(x) | rounded to a whole number, or the whole part |
| ABS(x) | the value without its sign |
| FLOOR(x [, significance]), CEILING(x [, significance]) | down or up to a multiple of the significance (default 1): FLOOR([Mileage], 1000) |
| MIN(a, b, ...), MAX(a, b, ...), AVG(a, b, ...), COUNT(a, b, ...) | over the values given |
| COUNT([column]), SUM([column]), AVG([column]), MIN([column]), MAX([column]) | over a group: all source facts that give the same derived fact - = COUNT([Incident Date]) the bad experiences of a driver, = MAX([Service Mileage]) the last service of a car (see Aggregates) |
| SQR, SQRT, EXP, LN, SIN, COS, TAN and their inverses | the usual mathematics |
Text
| Function | Result | Example |
|---|---|---|
| LEFT(text [, n]), RIGHT(text [, n]) | the first or last n characters (default 1) | LEFT([License Plate], 2) = NL |
| MID(text, start, n) | n characters from position start | MID("NL-K-903-LP", 4, 5) = K-903 |
| UPPER(text), LOWER(text) | in capitals, in small letters | |
| LEN(text) | the number of characters | |
| CONCAT(a, b, ...) | the texts joined | CONCAT([Pick Up Branch], "-", [Drop Off Branch]) |
In the DMN export
The DMN standard writes expressions in FEEL. When a decision table is exported to DMN, every formula is translated: each spreadsheet function has its FEEL equivalent.
| In CaseTalk | In FEEL |
|---|---|
| TODAY() | today() |
| DATE(y, m, d) | date(y, m, d) |
| YEAR(d), MONTH(d), DAY(d) | (d).year, (d).month, (d).day |
| DATEDIF(a, b, "Y") | years and months duration(a, b).years |
| DATEDIF(a, b, "M") | years and months duration(a, b).years * 12 + years and months duration(a, b).months |
| DATEDIF(a, b, "D") | (b - a).days |
| EDATE(d, n) | d + duration("P" + string(n) + "M") |
| IF(c, x, y) | if c then x else y |
| ABS, FLOOR, CEILING | abs, floor, ceiling |
| ROUND(x) | round half up(x, 0) |
| LEFT(t, n), RIGHT(t, n), MID(t, s, n) | substring(t, 1, n), substring(t, -n), substring(t, s, n) |
| UPPER, LOWER, LEN | upper case, lower case, string length |
| CONCAT(a, b) | a + b |
FEEL has no equivalent of YEARFRAC and of DATEDIF with "MD" or "YD": such a formula is exported as written, and the export report names it.
See also
- Decision Tables - business rules and derivable fact types as decision tables
- Constraints - value and frequency constraints that judge computed values
- Model Elements