# Top N Filter

This topic covers information about a filtering feature in FlexPivot, Top N Filter.

## Content

The Top N Filtering is the best option when you want to filter elements that have the highest values from a random list. **FlexPivot** also provides Bottom N Filtering to filter elements with the lowest values. A good example can be using Top N or Bottom N Filtering to display the top-selling or bottom-selling products for analyzing the sales performance.

![topnfilter](https://cdn.mescius.io/document-site-files/images/78f24d1c-0e57-452f-87a1-d318e186587a/images/topnfilter-1.gif)

## Top N Filtering with Code

In **FlexPivot**, you can apply Top N Filters using the [PivotFilter](/componentone/api/win/online-flexpivot/dotnet-standard-api/C1.PivotEngine/C1.PivotEngine.PivotFilter.html) class, which provides the [TopNValueField](/componentone/api/win/online-flexpivot/dotnet-standard-api/C1.PivotEngine/C1.PivotEngine.PivotFilter.TopNValueField.html) property to select a value field, the [TopNRule](/componentone/api/win/online-flexpivot/dotnet-standard-api/C1.PivotEngine/C1.PivotEngine.TopNRule.html) enumeration to choose between the top N or bottom N elements, and the **TopN** or **BottomN** properties to assign the number of elements to be filtered.

```vbnet
' Apply top n filtering
        Dim filter As C1.FlexPivot.C1FlexPivotFilter = fp.Fields("ProductName").Filter
        filter.Clear()
        filter.TopNValueField = fp.Fields("Quantity")
        filter.TopNRule = C1.FlexPivot.TopNRule.TopN
        filter.TopN = 3
```

```csharp
// Apply Top N Filter
C1.FlexPivot.C1FlexPivotFilter filter = fp.Fields["ProductName"].Filter;
filter.Clear();
filter.TopNValueField = fp.Fields["Quantity"];
filter.TopNRule = C1.FlexPivot.TopNRule.TopN;
filter.TopN = 3;
```

## Top N Filtering at Runtime

To display top N filtering at runtime:

1. Right click a field name. Click the **Field Settings** option to open the **Field Settings** dialog. This invokes the **Field Settings** dialog.
2. Select the **Top N** option in the filter dropdown menu.
3. In the **TopN** dialog, you can choose between **TopN** or **BottomN** and assign the number of elements to be filtered. You can also assign a value field in the **by value** option.