◷ Reading Time: 12 minutes
The Result Decision Table
In this example of modeling a Decision Table, we picked the table from a previous article.
Destination | Age | IsWeekDay | MoreThan6 | Discount |
Group1 | 100 | |||
India | Group2 | Y | 40 | |
India | Group2 | N | 50 | |
Group3 | Y | N | 0 | |
Group3 | Y | Y | 10 | |
India | Group3 | N | Y | 30 |
India | Group3 | N | N | 20 |
Asia | Group2 | Y | Y | 50 |
Asia | Group2 | Y | N | 40 |
Asia | Group2 | N | Y | 75 |
Asia | Group2 | N | N | 65 |
Asia | Group3 | N | Y | 35 |
Asia | Group3 | N | N | 25 |
With a slight change (adding a row) to this table, the model is ready.
Decision Table in a Spreadsheet
So far the prepared table has the following:
- All the conditions required for the decision (Check Conditions)
- An action for each rule (Check Actions)
- Column names
In order to execute the decision, there are some additional rows that need to be added to the table in order to make it executable:
Question: What is the input of this Decision Table?
Answer: The data type we prepared for the decision that encapsulates all of the columns of the table (excluding the action columns) as properties of the type. Let’s call it model
Additional row: Input model
Question: What is the goal of this Decision Table? What does it try to achieve?
Answer: The discount percentage for different scenarios.
Additional row: Output discount
Question: How does the data in the table relate to the model?
Answer: The attributes of the model are the properties shown in each column. The actions (goals of the decision) are located in the last column.
Additional rows:
Destination | Age | IsWeekDay | MoreThan6 | Discount |
---|---|---|---|---|
Condition | Condition | Condition | Condition | Action |
model.Destination | Age | IsWeekDay | MoreThan6 | discount |
Note that in the last new row we added, we connected the data to the Input and Output of the Decision Table. You can use $value as a replacement for the cell values from your table.
In the condition column, you can use expressions to establish the relationship between the values and the condition. As we are simply going to set the discount value in the Action column, we use assignment expression to assign a value to discount. Now you can understand where those rows originate.
Modeling Using Excel
In a spreadsheet (e.g., MS Excel-based Decision Tables), the properties of a Decision Table can be defined as shown below:
- Title
- Header
- Input
- Output (optional)
- Import (optional)
- Column Type
- Expression (formula)
- Column Name
- Empty row
- Data rows (values/expressions)
You can have all of the rows above defined in an Excel-based Decision Table
Title
The Decision Table must start with a Decision keyword and then a name in the first row.
Format: Decision [decision name]
To finalize the signature part of the Decision Table, after the row containing the column name, there must be an empty row and then your data in the table may begin. All done. The decision table is modeled.
Header
Input
Allows adding input parameters with series of comma-separated variable names
Format: Input v1,v2,v3...
Output
Allows defining output [parameter] with adding a series or comma-separated variable names
Format: Output v1, v2, v3...
Import
Allows the addition of a type parameter and usage of the Type’s static members
Format: Import fullTypeName
For example, Import System.DateTime will enable you to use DateTime.Now in your rules expression
Building Sample
You can build an Excel spreadsheet that has the following structure:
Decision discount percentage | ||||
Input model | ||||
Output discount | ||||
Condition | Condition | Condition | Condition | Action |
model.Destination | model.Age | model.IsWeekDay | model.MoreThan6 | discount |
Destination | Age | IsWeekDay | MoreThan6 | Discount |
Group1 | 100 | |||
India | Group2 | Y | 40 | |
India | Group2 | N | 50 | |
Group3 | Y | N | 0 | |
Group3 | Y | Y | 10 | |
India | Group3 | N | Y | 30 |
India | Group3 | N | N | 20 |
Asia | Group2 | Y | Y | 50 |
Asia | Group2 | Y | N | 40 |
Asia | Group2 | N | Y | 75 |
Asia | Group2 | N | N | 65 |
Asia | Group3 | N | Y | 35 |
Asia | Group3 | N | N | 25 |
Default Compare Operator
As you can see in the condition columns, we just compare the properties value of the object to the cell values. Where is the compare operator? By default, in condition columns, the compare operation is the equal operator or ==, which can be eliminated. So for example in the first column (condition for Destination), instead of writing model.Destination==$value we can just write model.Destination.
This default operator behaviour can simplify the Decision Tables a lot.
Cell Values
Cells can simply be values or expressions: The Decision Table can have many different expressions:
- Simple values
- Partial conditions
- Range expressions
- … and more, which you can learn about at Decision Table Expressions.
Authoring Decision Table
Using Excel
Simply copy and paste the table into MS Excel or Google Documents, for instance. Save the Excel spreadsheet to something like DecisionTable.xlsx.

If you don’t have MS Excel, you can use Google Documents and create a spreadsheet to author the rule.

Using Visual Designer
Using Decision Table Editor over a generic Spreadsheet document has its own advantages.
- You can simply validate the document and find any overlaps by pressing the validate button on the FlexRule Designer. Please have a look at Model Validation to see how it works.
- Allows expression builder to help you build the values and expressions
- Has information and context about the whole rule project and relations of the logic and how it fits into scenarios (e.g., IN DMN for Flow scenario).
- You can link back and forth to the Decision Table and trace and track its usages
A picture of the Decision Table Editor is shown below:

Using XML
In XML language, you need to fill the following structure.
<DecisionTable name="discount percentage">
<Declaration>
<!-- Input, Output and Type definitions come here -->
</Declaration>
<Columns>
<!-- Table signature comes here -->
</Columns>
<Data>
<!-- Table data comes here between series of 'Row' and 'Value' elements
in which each row contains multiple value entries as a text element
The data section represents the condition's expressions.
These can be as simple values (data) or as complex expressions.
-->
</Data>
</DecisionTable>
For this example, the following Xml is the completed model:
<DecisionTable name="discount percentage">
<Declaration>
<Define name="model" direction="in"/>
<Define name="discount" direction="out"/>
</Declaration>
<Columns>
<Condition name="Destination" expression="model.Destination"/>
<Condition name="Age" expression="model.Age"/>
<Condition name="IsWeekDay" expression="model.IsWeekDay"/>
<Condition name="MoreThan6" expression="model.MoreThan6"/>
<Action name="Discount" expression="discount"/>
</Columns>
<Data>
<Row><Value></Value><Value>Group1</Value><Value></Value><Value></Value><Value>100</Value></Row>
<Row><Value>India</Value><Value>Group2</Value><Value></Value><Value>Y</Value><Value>40</Value></Row>
<Row><Value>India</Value><Value>Group2</Value><Value></Value><Value>N</Value><Value>50</Value></Row>
<Row><Value></Value><Value>Group3</Value><Value>Y</Value><Value>N</Value><Value>0</Value></Row>
<Row><Value></Value><Value>Group3</Value><Value>Y</Value><Value>Y</Value><Value>10</Value></Row>
<Row><Value>India</Value><Value>Group3</Value><Value>N</Value><Value>Y</Value><Value>30</Value></Row>
<Row><Value>India</Value><Value>Group3</Value><Value>N</Value><Value>N</Value><Value>20</Value></Row>
<Row><Value>Asia</Value><Value>Group2</Value><Value>Y</Value><Value>Y</Value><Value>50</Value></Row>
<Row><Value>Asia</Value><Value>Group2</Value><Value>Y</Value><Value>N</Value><Value>40</Value></Row>
<Row><Value>Asia</Value><Value>Group2</Value><Value>N</Value><Value>Y</Value><Value>75</Value></Row>
<Row><Value>Asia</Value><Value>Group2</Value><Value>N</Value><Value>N</Value><Value>65</Value></Row>
<Row><Value>Asia</Value><Value>Group3</Value><Value>N</Value><Value>Y</Value><Value>35</Value></Row>
<Row><Value>Asia</Value><Value>Group3</Value><Value>N</Value><Value>N</Value><Value>25</Value></Row>
</Data>
</DecisionTable>
Now you are able to read the model by using XmlTableReader
private static IIterable<IElementModel> LoadDecisionTableModel()
{
// Load the excel document
var reader = new XmlTableReader(File.ReadAllBytes(@"DecisionTable.xml"));
reader.Entries.Add("Y", "true", true);
reader.Entries.Add("N", "false", true);
// Reads all the tables in a specific sheet
IIterable<ITable> tables = reader.GetTables();
// Create parser for table
ITableParser tableParser = TableParser.CreateParser();
// Parse the tables to model
return tableParser.Parse(tables);
}
Executing a Decision Table Model
By defining the aging group as an Enum type
enum AgeGroup
{
Group1,
Group2,
Group3
}
Executing the Decision Table is simple. What you need to do is create an execution plan and engine, then execute and retrieve the discount value.
// Load an engine instance and configure custom entries (when required)
var engine = RuntimeEngine.FromSpreadSheet(File.OpenRead(@"YOUR_EXCEL_FILE.xlsx"), "YOUR_SHEET_IN_EXCEL");
engine.OnRunning = (ae) => ae.Context.VariableContainer.RegisterFunction(typeof(AgeExtensions));
// Note you can load the custom entries from config file as well.
engine.Entries.Add("Y", "true", true);
engine.Entries.Add("N", "false", true);
// Creating the input model
var sampleData = new
{
Age = AgeGroup.Group3,
Destination = "India",
MoreThan6 = false,
IsWeekDay = false,
};
// Call run method of engine and pass your input object
var result = engine.Run(new object[] { sampleData });
// Reading the discount value from the result that is returned by the Run method
var discount = result.VariableContainer["discount"];
Logic Model Reflection
And you are ready to read the table as a model in your application by using ExcelTableReader.
private IIterable<IElementModel> LoadDecisionTableModel()
{
// Load the excel document
var reader = new ExcelTableReader(@"DecisionTable.xlsx", "Sheet1");
reader.Entries.Add("Y", "true", true);
reader.Entries.Add("N", "false", true);
// Reads all the tables in a specific sheet
IIterable<ITable> tables = reader.GetTables();
// Create parser for table
ITableParser tableParser = TableParser.CreateParser();
// Parse the tables to model
return tableParser.Parse(tables);
}
Please note: The application that is executing the code DOES NOT need to have an Excel application or third-party component installed.
What’s next?
- Introduction to decision tables
- Preparing a decision table
- Modeling decision table
- Decision Model and Notation – decision table
- Check overlaps
- Decision Table final logic
- Multilingual decision table
- Decision Table 101