Conditional Formatting

  • 7 min to read

The Dashboard Designer control supports conditional formatting. This feature allows you to highlight cell values in the Grid and Pivot Grid that meet the specified criteria.

BlogDashboard_ConditionalFormatting

Format Rules

You can apply conditional formatting to measure or dimension values. The table below lists format conditions that can be applied to different types of data items.

Data Item

Supported Format Conditions

Measure/numeric Dimension

Value

Top-Bottom

Average

Expression

Icon Ranges

Color Ranges

Gradient Ranges

Bar

Bar Color Ranges

Bar Gradient Ranges

string Dimension

Value with the condition type set to Equal To, Not Equal To or Text that Contains

Expression

date-time Dimension

Value

A Date Occurring for dimensions with the continuous date-time group interval

Expression

Icon Ranges

Color Ranges

Gradient Ranges

Bar

Bar Color Ranges

Bar Gradient Ranges

Create a Format Rule

Click the measure/dimension menu button, select Add Format Rule and choose the condition:

AddFormatRule_ValueItem

Specify appearance settings and set a condition for the format rule. Available settings depend on the selected format rule. The image below displays the Greater Than dialog corresponding to the Value format condition for the Grid dashboard item:

GreaterThanDialog

Specify a data item which is used to calculate a condition. You can create a format rule for one data item and apply new appearance settings to the other data item. You can also create format rules for hidden measures and apply formatting to values of visible data items.

Appearance Settings

Follow the steps below to configure and customize the current format condition's appearance settings:

  • Choose the predefined background color/font or click an empty square to add a new preset in the Appearance tab.

    NewRuleDialog_AppearanceTab

  • Add the predefined icon in the Icons tab.

Edit a Format Rule

Click the Edit Rules button in the Home ribbon tab to edit format rules for the selected dashboard item:

EditRules_Ribbon

You can also invoke the Edit Rules item in the data item's menu or in the dashboard item's context menu:

EditRulesMenuItem

The Edit Rules dialog contains format rules applied to the dashboard item:

EditRulesDialog

  • To edit the selected rule, use the Edit button or double-click the rule.
  • To delete the selected rule, use the Delete button.
  • To reorder format rules, use the Up (EditRules_UpButton and Down (EditRules_DownButton buttons. You can reorder rules to specify their priority.
  • To enable/disable a rule, use the corresponding check box in the left column.
  • To create a new rule, click the Add button and select the format condition. The calculated by combo box allows you to select the measure/dimension which is used to apply a format rule.
  • To filter format rules by the specified data item, use the Filter by combo box.

To clear all rules for the specified data item, use the Clear Rules button in the data item's context menu.

Grid Settings

The Grid dashboard item applies conditional formatting to data items which provide data to the dimension and measure column types.

You can use hidden measures to specify a condition used to apply formatting to visible values.

The Apply to row check box in the format rule's dialog specifies whether to apply the formatting to the entire grid row.

Create a Format Rule in Code

Create the GridItemFormatRule object and specify its settings to add a format rule:

Enable the CellsItemFormatRule.ApplyToRow flag to apply formatting to the entire grid row.

You can use the DashboardItemFormatRule.Enabled property to disable the current format rule.

The following code snippet shows how to apply the Top-Bottom (FormatConditionTopBottom) format condition to highlight the three topmost values:

GridItemFormatRule topRule = new GridItemFormatRule(extendedPrice, salesPerson);
FormatConditionTopBottom topCondition = new FormatConditionTopBottom();
topCondition.TopBottom = DashboardFormatConditionTopBottomType.Top;
topCondition.RankType = DashboardFormatConditionValueType.Number;
topCondition.Rank = 3;
topCondition.StyleSettings = new IconSettings(FormatConditionIconType.IndicatorGreenCheck);
topRule.Condition = topCondition;

grid.FormatRules.Add(topRule);
TIP

Refer to the Conditional Formatting section for more examples.

Pivot Settings

The Pivot dashboard item applies conditional formatting to measures placed in the Values section and dimensions placed in the Columns or Rows sections.

You can use hidden measures to specify a condition used to apply formatting to visible values.

The format rule's dialog contains the following Pivot-specific settings:

Option Description
Enabled Enables/ Disables the current format rule.
Intersection Mode Specifies the level on which to apply conditional formatting to pivot cells.
Intersection Row/Column Dimension Applies the format rule to the specified row/column dimension, if you select the Specific Level as the intersection mode.
Apply to Row/Column Specifies whether to apply the formatting to the entire Pivot's row/column.

The Pivot item allows you to specify to which field intersection a format rule is applied.

Intersection Level Mode Description
Auto Identifies the default level. For the Pivot dashboard item, Auto identifies the First Level.
First Level The first level values are used to apply conditional formatting.
Last Level The last level values are used to apply conditional formatting.
All Levels All pivot data cells are used to apply conditional formatting.
Specific Level The specified measures / dimensions are used to apply conditional formatting.

The image below displays different intersection levels with the applied conditional format rule:

winforms_pivot_intersection_level_mode

To apply a format rule to the row or column Grand Total, change the Intersection Level Mode to Specific level and set the [Grand Total] value as the intersection row/column dimension.

Note the following limitations:

  1. The dashboard cannot calculate conditional formatting in the Pivot Grid for multiple levels for ranges with percentage values. In this case, the "All Levels" intersection mode is not available for a conditional formatting rule.
  2. The format condition dialog does not contain any Pivot-specific settings for a dimension from Columns and Rows.

Create a Format Rule in Code

Create the PivotItemFormatRule object and specify its settings to add a format rule:

Enable the CellsItemFormatRule.ApplyToRow/PivotItemFormatRule.ApplyToColumn properties to apply formatting to the entire pivot row/column.

You can use the DashboardItemFormatRule.Enabled property to disable the current format rule.

The following code snippet shows how to apply the Top-Bottom (FormatConditionTopBottom) format condition to highlight three topmost values:

PivotItemFormatRule lastLevelRule = new PivotItemFormatRule(pivot.Values[0]);
FormatConditionRangeGradient rangeCondition =
    new FormatConditionRangeGradient(FormatConditionRangeGradientPredefinedType.WhiteGreen);
lastLevelRule.Condition = rangeCondition;
lastLevelRule.IntersectionLevelMode = FormatConditionIntersectionLevelMode.LastLevel;

PivotItemFormatRule topCategoryRule = new PivotItemFormatRule(pivot.Values[0]);
FormatConditionTopBottom topCondition = new FormatConditionTopBottom();
topCondition.TopBottom = DashboardFormatConditionTopBottomType.Top;
topCondition.RankType = DashboardFormatConditionValueType.Number;
topCondition.Rank = 3;
topCondition.StyleSettings = new IconSettings(FormatConditionIconType.RatingFullGrayStar);
topCategoryRule.Condition = topCondition;
topCategoryRule.IntersectionLevelMode = FormatConditionIntersectionLevelMode.SpecificLevel;
topCategoryRule.Level.Row = pivot.Rows[0];
topCategoryRule.DataItemApplyTo = pivot.Rows[0];

pivot.FormatRules.AddRange(lastLevelRule, topCategoryRule);
TIP

Refer to the Conditional Formatting section for more examples.