Use conditional formatting rules in Data Studio
You can style the data in your charts based on certain conditions. For example, if Campaign is "Summer Sale," then set the entire table row font color to green, or if Sales is less than Forecast, set the scorecard background color to red.
- Edit your report.
- Select a supported chart (see the limits section below).
- On the right, click STYLE.
- At the top, in the Conditional formatting section, click + Add.
- Define the format rules.
- Define the color and style to apply when the format rules are met.
- Click Save.
In this article:
How conditional formatting works
Conditional formatting evaluates one or more format rules and applies color and style to the fields in your chart that satisfy those rules. Currently, you can apply these rules in tables and scorecards.
If you switch a chart's visualization to a different type (for example, a table to a scorecard), conditional formatting will continue to work as long as the fields and values used in the formatting rules still exist in the new chart. Rules based on fields or values that aren't in the new visualization are ignored.
Create format rules
Format rules are comparison conditions that determine when to apply different color and style. You can compare a single field in the chart to a literal value (for example, Campaign = Summer Sale), or to another field (Actual Sales < Forecast Sales). Format rules can only use fields currently contained in the chart.
Rule comparison operators
The comparison operators available depend on the type of field you're comparing to. For example, if you select a numeric field, you can use operators such as:
- Equal to
- Not equal to
- Greater than
- Less than or equal to
For text fields you can create conditions using:
- Equal to
- Not empty
For Boolean (logical) fields, you can also use:
- Is TRUE
- Is FALSE
Format rule order
The order in which you specify format rules can be important. Multiple rules in a chart are evaluated in descending order, and the last set of true conditions found is the one that is applied. For example, say you've got three rules in a table:
- Rule 1 sets both the font color and background color.
- Rule 2 sets the font color.
- Rule 3 sets the background color.
When all 3 rules are true, you'll get the font color from rule 2 and the background color from rule 3. Rule 1 will be ignored, as shown below:
You can reorder rules using the drag bars on the left. Here's what happens when we move rule 3 to the top:
In this example, the background color from rule 1 carries through the following rules and is applied to the table.
Format rules, percentages, and decimal precision
Bounce rate > .512
Select any field
To build a condition that returns true if any field in the chart matches your rule, click Select a field, then click Select any field.
- Select any field.
When this option is selected, the format rule displays "Values," indicating that the rule applies to any values found in the chart.
Set color and style
Color and style rules determine which data to format and how to format it. You can format the entire table row, a specific field value, or any value that matches, regardless of which field it occurs in.
Format the entire row
The Entire row option applies the format to every row in the table that matches the condition.
Format a specific field
You can format a specific field in a table. Click the field selection drop-down menu and select the field you want to format.
The Cells option applies to scorecards, and to rules using Select any field in a table. This option applies the color and style to the scorecard metric, or to the values that match the table's format rule.
Edit and delete rules
- Edit your report.
- Select the chart with the rule you want to edit.
- On the right, Click STYLE.
- At the top, in the Conditional formatting section, click Edit, then for the rule you want to change, click Edit or Remove.
Copy conditional formatting rules
There are 2 ways to duplicate conditional formatting rules:
- Copy and paste a chart with conditional formatting to create a new chart with those same rules.
- Copy a chart with conditional formatting, then use Edit > Paste special > Paste style only to apply that chart's conditional formatting to an existing chart.
Limits of conditional formatting
- Conditional formatting is currently available for tables and scorecards.
- You can have up to 10 format rules per chart.