windowsforms-18037-controls-and-libraries-spreadsheet-examples-filter-data-how-to-apply-a-dynamic-filter.md
This example demonstrates how to apply a dynamic filter to a column.
The dynamic filter allows you to apply one of the predefined date filters to display date values that fall within a specified time period (next, this or last week, month, year, etc.), or to display numbers that are above or below the average.
Note
The dynamic filter criteria can change when the data to which the filter is applied or the current system date changes.
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);
// Apply a dynamic filter to the "Sales" column to display only values that are above the average.
worksheet.AutoFilter.Columns[2].ApplyDynamicFilter(DynamicFilterType.AboveAverage);
// Apply a dynamic filter to the "Reported Date" column to display values reported this year.
worksheet.AutoFilter.Columns[3].ApplyDynamicFilter(DynamicFilterType.ThisYear);
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)
' Apply a dynamic filter to the "Sales" column to display only values that are above the average.
worksheet.AutoFilter.Columns(2).ApplyDynamicFilter(DynamicFilterType.AboveAverage)
' Apply a dynamic filter to the "Reported Date" column to display values reported this year.
worksheet.AutoFilter.Columns(3).ApplyDynamicFilter(DynamicFilterType.ThisYear)