# Top, Bottom, or Average Rules

Learn how to apply top, bottom, or average rules to format cells based on specific values or percentiles with Spread.NET's conditional formatting feature.

## Content

The top or bottom rules apply formatting to cells whose values fall in the top or bottom percent. The top ranked rule specifies the top or bottom values. The average rule applies to the greater or lesser average value of the entire range.
The following figure shows a top rule that sets the style for the above average value in the range of values; the code to create the example is provided in the example.
![Top Rule Example](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/averagerule.png)
The following options are available:

* top 10
* top 10%
* bottom 10
* bottom 10%
* above average
* below average

## Using Code

1. Set the properties of the rule class.
2. Apply the formatting.

## Example

This example code creates an average rule and uses the [SetConditionalFormatting](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.SetConditionalFormatting.html) method to apply the rule.

```csharp
private void Form1_Load(object sender, EventArgs e)
        {
            fpSpread1.Sheets[0].Cells[0, 0].Value = 3;
            fpSpread1.Sheets[0].Cells[1, 0].Value = 2;
            fpSpread1.Sheets[0].Cells[1, 1].Value = 10;
            fpSpread1.Sheets[0].Cells[0, 2].Value = 1;          
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Average CF
            FarPoint.Win.Spread.AverageConditionalFormattingRule average = new FarPoint.Win.Spread.AverageConditionalFormattingRule(true, true);
            average.IsAbove = true;
            average.IsIncludeEquals = true;
            average.StandardDeviation = 2;
            average.FontStyle = new FarPoint.Win.Spread.SpreadFontStyle(FarPoint.Win.Spread.RegularBoldItalicFontStyle.Bold);
            fpSpread1.ActiveSheet.SetConditionalFormatting(1, 1, average);
        }
```

```vbnet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        fpSpread1.Sheets(0).Cells(0, 0).Value = 3
        fpSpread1.Sheets(0).Cells(1, 0).Value = 2
        fpSpread1.Sheets(0).Cells(1, 1).Value = 10
        fpSpread1.Sheets(0).Cells(0, 2).Value = 1
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Average CF
        Dim average As New FarPoint.Win.Spread.AverageConditionalFormattingRule(True, True)
        average.IsAbove = True
        average.IsIncludeEquals = True
        average.StandardDeviation = 2
        average.FontStyle = New FarPoint.Win.Spread.SpreadFontStyle(FarPoint.Win.Spread.RegularBoldItalicFontStyle.Bold)
        fpSpread1.ActiveSheet.SetConditionalFormatting(1, 1, average)
    End Sub
```

## Using the Spread Designer

1. In the work area, select the cell or cells for which you want to set the conditional format.
2. Under the **Home** menu, select the **Conditional Formatting** icon in the **Style** section, then select the **Top/Bottom Rules** option, and then choose the condition.
3. From the **File** menu choose **Apply and Exit** to apply your changes to the component and exit Spread Designer.

## See Also

[Color Scale Rules](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-interact-condition/spwin-interact-conditional/spwin-interact-scales)
[Data Bar Rule](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-interact-condition/spwin-interact-conditional/spwin-interact-condbar)
[Icon Set Rule](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-interact-condition/spwin-interact-conditional/spwin-interact-iconset)
[Highlighting Rules](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-setappearance/spwin-interact-condition/spwin-interact-conditional/spwin-interact-condhigh)