[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Expand]Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [Expand]Formatting Cells
   [Collapse]Conditional Formatting
     How to: Format Cell Values that are Above or Below the Average
     How to: Format Cells that are Between or Not Between Two Values
     How to: Format Top or Bottom Ranked Values
     How to: Format Cells based on the Text in the Cell
     How to: Format Unique or Duplicate Values, Blank Cells and Formula Errors
     How to: Format Cells that Contain Dates
     How to: Format Cells that are Less than, Greater than or Equal to a Value
     How to: Use a Formula to Determine which Cells to Format
     How to: Format Cells Using a Two-Color Scale
     How to: Format Cells Using a Three-Color Scale
     How to: Format Cells Using Data Bars
     How to: Format Cells Using Icon Sets
   [Expand]Group Data
   [Expand]Filter Data
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Format Cell Values that are Above or Below the Average

This example demonstrates how to apply an "above or below average" conditional formatting rule to a range of cells.

  1. To create a new conditional formatting rule represented by the AverageConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddAverageConditionalFormatting method. Pass the following parameters:

    If you use the overloaded method with three parameters, pass the third parameter:

    • An integer value representing a number of standard deviations to be included above or below the mean in a range of cells.
  2. Specify formatting options to be applied to cells if the condition is true using the ISupportsFormatting.Formatting property of the AverageConditionalFormatting object. Set the background color and specify the font attributes.

To remove the AverageConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

The image below shows the result (the workbook is opened in Microsoft® Excel®). Cost values above the average in the first quarter are highlighted in yellow with a red font color and cost values one standard deviation below the average in the second quarter are highlighted in light-green with a blue-violet font color.

Is this topic helpful?​​​​​​​