DMN Demystified, Part 3. Key Element 2: Decision Table

DecisionTable

A second key feature supported by every DMN tool is the decision table. In DMN, decision tables are one form of expression used to determine the value of a decision or BKM. Decision tables have been around for 40 years, but DMN defines specific formats and rules for their construction. In one common format, the columns of the table represent inputs and outputs, and the rows represent decision rules. The combination of an input column heading, called input expression, and an input table cell, called input entry, defines a Boolean expression. If that expression is true for each column in a rule, the rule is said to match and its output entry is selected as the table’s output value. An input entry of hyphen (-) means that input is irrelevant to the rule.

For example, rule 1 in the table in the diagram means

If Customer= "Business" and OrderSize<10 then Discount=0.10
and rule 3 means
If Customer= "Private" then Discount=0.05
In this diagram – in fact, in all the diagrams in the DMN spec – the input entries all reference literal values, but this is misleading. Input entries and output entries both may reference variables representing decision inputs, not just literal values. So decision tables can actually support much richer decision logic than suggested by the examples in the spec.

The expressions within a rule are always ANDed together. On the other hand, the rules in the table are ORed together, so that more than one rule may match. In that case, the table’s hit policy is used to select the output value. The default hit policy, Unique (U), means that only one rule may match. Hit policy Any (A) means that multiple rules may match but all give the same output value. Hit policy Priority (P) means that the output with the highest priority is selected, where priority is given by the listed order of allowed values in the output column heading. Hit policy First (F) means select the output of the first rule that matches. Because decision table logic is supposed to be declarative, hit policy F is semi-deprecated. It is also possible to generate a list of outputs from the matching rules using hit policy Collect (C).

Decision table logic is explicitly declarative. The order of the columns and rows (except for the hit policy First) makes no difference in the result.

Since a decision table is an expression, technically it doesn't have a name. Its output takes its name from the decision or BKM that contains it, which is also the name of the variable (InformationItem) that stores the output value and makes it available to the decision logic of dependent decisions. But as you see in the figure, the label heading the output column may be anything you like.