DMN Expression Types Reference¶
DMN (Decision Model and Notation) provides a powerful set of expression types that can be combined to model complex decision logic. When defining decision logic in the DMN editor, you'll select from these expression types through the "Select expression" menu.
Expression Types¶
Detailed Expression Type Examples¶
Literal Expression¶
The simplest expression type in DMN, used for direct values or FEEL expressions.
Relation¶
The most widely used DMN expression type, with columns for input conditions and output conclusions.
State | Abbreviation |
---|---|
"Florida" | "FL" |
"North Carolina" | "NC" |
"New York" | "NY" |
Decision Table¶
The most widely used DMN expression type, with columns for input conditions and output conclusions.
U | Credit Score | Risk Rating |
---|---|---|
1 | >= 700 | "Low" |
2 | [600..700) | "Medium" |
3 | < 600 | "High" |
Context¶
Defines key-value pairs that can be used for multi-step calculations.
{
Base Amount: 100,
Tax Rate: 0.07,
Tax Amount: Base Amount * Tax Rate,
Total: Base Amount + Tax Amount,
result: Total
}
List¶
Creates an ordered collection of values or expressions.
Invocation¶
Calls a Business Knowledge Model (BKM) or function.
Function¶
Defines a reusable function with parameters.
function(age, income)
if age < 25 then income * 0.1
else if age < 65 then income * 0.15
else income * 0.05
Conditional¶
Creates branching logic with if-then-else statements.
For Loop¶
Iterates over items in a list or collection.
Every¶
Tests if a condition is true for every item in a collection.
Some¶
Tests if a condition is true for at least one item.
Filter¶
Filters a collection based on a condition.
Hit Policies in Decision Tables¶
Decision tables use hit policies to determine how rules are applied:
Symbol | Name | Description |
---|---|---|
U | Unique | Each row must be unique and only one rule can match (most common) |
A | Any | Multiple rules can match but must return the same output |
P | Priority | Multiple rules can match, but the output of the first matching rule is used |
F | First | Multiple rules can match, but the first matching rule (by rule order) is used |
C | Collect | Multiple rules can match and all are collected |
C+ | Collect (Sum) | Collects and sums numeric results |
C< | Collect (Min) | Collects and returns the minimum value |
C> | Collect (Max) | Collects and returns the maximum value |
C# | Collect (Count) | Counts the number of matching rules |
FEEL Operators and Functions¶
When writing expressions, you'll often use FEEL operators and functions:
Comparison Operators¶
=
,!=
: Equal, not equal>
,<
,>=
,<=
: Greater than, less than, etc.[..], (..)
: Inclusive and exclusive ranges (e.g.,[5..10]
)
Logical Operators¶
and
,or
,not
: Logical operators
Collection Operators¶
in
: Membership test (e.g.,x in [1,2,3]
)satisfies
: Test if collection elements meet a condition
Common Functions¶
count(collection)
: Count elementssum(collection)
: Sum numeric valuesmin(collection)
,max(collection)
: Find minimum/maximumsubstring(string, start, length)
: Extract substringcontains(collection, element)
: Test for elementlist contains(collection, element)
: Test if list contains element
Combining Expression Types¶
DMN's power comes from combining these expression types to create sophisticated decision logic. For example:
{
High Value Items: Order.items[price > 100],
Discount Eligible: some i in High Value Items satisfies i.category = "Electronics",
Discount Rate: if Discount Eligible then 0.15 else 0.05,
Discount Amount: sum(for i in Order.items return i.price * i.quantity) * Discount Rate,
result: Discount Amount
}
This context expression combines filtering, some, conditional, for loop, and mathematical operations to calculate a discount based on complex criteria.