Within the Rulestar system, fields with options (select, radio and checkbox fields) can be used in calculations when their option values are numeric (except for the "Count" method explained below). A common usage of calculations using fields with options is counting the number of "Yes" responses over a number of Yes/No question. Here, each "Yes" and "No" label is given the value of 1 and 0 respectively.
In the examples that follow, @123 represents a field with options.
In addition to the basic operators (addition, subtraction etc) that are used in calculations using number fields, fields with options have four option properties that can be accessed through Rulestar's calculation interface. They are:
- Options.Max, and
The first three properties, "Options.Sum", "Options.Min" and "Options.Max" only exist when all option values are numeric:
- @123.Options.Sum returns the sum of the values of all options,
- @123.Options.Min returns the minimum value of all options, and
- @123.Options.Max returns the maximum value of all options.
@123.Options.Count returns the total number of options a field has (and exists if the option values are numeric or not).
Accessing each property is easy - simply select the desired field in the calculation builder and complete the calculation by typing desired property eg, ".Options.Count". For example:
Remember, when accessing an "Options" property, the calculation will consider all field options (not those selected).
Checkbox fields are unique in that they can have more than one option selected. This means that checkbox fields have additional properties, being the properties of the options selected.
In addition to the four properties listed above, you can use the following four properties:
- Max, and
As with the "Options" properties, the first three properties, "Sum", "Min" and "Max" only exist when all option values are numeric:
- @123.Sum returns the sum of the values of the selected options,
- @123.Min returns the minimum value of the selected options, and
- @123.Max returns the maximum value of the selected options.
@123.Count returns the total number of options selected (and exists if the option values are numeric or not).
Min and Max are only valid for required fields.
Please see this demonstration of this calculation.