Apply multiple style conditions

In our guide Use parameters with expressions we demonstrated how to apply conditional styling. With ReportBro v3.3 we introduced a new feature that allows for a more sophisticated approach: You can apply multiple conditional styles based on a set of rules.

In this tutorial you will learn to:
Apply a conditional style
Apply multiple conditional styling rules

1 Apply a conditional style

Let's take the example of simplifying the display of the total sugar content in food. We have a list of food products and each product contains a certain percentage of sugar. We'd like to highlight sugar-free products and label sugary products according to the sugar content they contain.

We prepared a parameter list products with parameters
- name (text)
- sugar_content (number)
and inserted a table with assigned parameters (look at the guide Creating tables for further explanation if needed).

We'd like to highlight all sugar-free products. So let's click the table column holding the parameter sugar_content and open the conditional style section in the detail panel. We set the condition ${sugar_content} == 0 and apply green background color as styling.

2 Apply multiple conditional styling rules

The result of step 1 is to simply highlight sugar-free products. However, we'd like to differentiate the background color according to the percentage of sugar in the product. So let's go back to the table column that we'd like to style and open the conditional style section in the detail panel again.

First of all, we need to adapt the condition from step 1 so that it applies to all products: ${sugar_content} >= 0. This results in highlighting all products with green background color.

Next, we need to create style templates which can be applied for further conditions - let's have yellow, orange and red to distinguish the sugar level contained in the product.

Now we are ready to create additional rules in the conditional style section. Let's define different conditions and apply a style template to each. ReportBro applies rules based on their order, the first applicable condition is served. That means, it's important to order conditions from top to bottom - in our case from high sugar content (red) to low (yellow).

Print it like a Bro

Let's have a look at the result. Looks like our diet can soon become more balanced.

Bro tips for multiple style conditions

The basic condition in the conditional style section must evaluate to true:
If this condition isn't met ReportBro doesn't evaluate additional rules
Order conditions from top to bottom:
ReportBro evaluates until the first condition is met

Try it yourself: Download the report of this tutorial
Read here how to import the report into ReportBro Designer.

Want to know more about tables? Read our tutorials for
Creating tables,
Condition-based table column printing and
Table grouping

By the way, ReportBro is also available for everyone as open-source on github (see Download page). Star us on github if you like what you see!