Skip to main content

Filter the Extract Data Source

  • 3 minutes to read

You can filter Extract Data Source data in the Dashboard Designer or in code.

Use the Dashboard Designer to Apply a Filter

To apply a filter to a data source, click the Filter button in the Data Source Ribbon tab.

DataSourceFiltering_FilterButton_Ribbon

This invokes the Filter Editor dialog that allows you to build filter criteria:

DataSourceFiltering_FilterEditor

Tip

Documentation: Filter Editor

To clear the data source filter, use the Clear Filter button in the Data Source Ribbon tab.

Pass Parameter Values

You can use the Filter Editor to filter a data source according to the current parameter value. See the Pass Parameter Values topic for details.

Specify Filter Criteria in Code

To specify filter criteria in code, use the following properties:

ExtractSourceOptions.Filter
Specifies the logical expression that filters rows to be included in a data extract.
DashboardExtractDataSource.Filter
Specifies the logical expression that filters data to be displayed in a dashboard. Users can change or clear this filter in the UI.

Example

The following code sample shows how to create a data extract from the Excel data source and filter the extracted data:

ExtractSourceOptions.Filter
Specifies the [CategoryName] = 'Beverages' expression. This expression allows you to include only rows related to the Beverages category in the data extract.
DashboardExtractDataSource.Filter
Filters data loaded to a dashboard from the created extract data source. The following expressions allows you to display only the Chai product: [ProductName] = 'Chai'.

As a result, the Grid dashboard item displays the sales of the Chai product from the Beverages category for each seller:

extract-filtering-example

using DevExpress.DashboardCommon;

namespace ExtractFiltering {
    public partial class DesignerForm1 : DevExpress.XtraBars.Ribbon.RibbonForm {
        public DesignerForm1() {
            InitializeComponent();
            dashboardDesigner.CreateRibbon();
            dashboardDesigner.LoadDashboard(@"Dashboards\dashboard1.xml");
            // Creates an origin Excel Data Source.
            DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource() {
                FileName = @"..\..\Data\SalesPerson2.xlsx",
                SourceOptions = new DevExpress.DataAccess.Excel.ExcelSourceOptions (
                new DevExpress.DataAccess.Excel.ExcelWorksheetSettings() {
                    WorksheetName = "Sheet1",
                })
            };
            // Creates a data extract based on the Excel Data Source.
            DashboardExtractDataSource dataExtract = new DashboardExtractDataSource();
            dataExtract.ExtractSourceOptions.DataSource = excelDataSource;
            dataExtract.FileName = @"..\..\Data\Extract1.dat";
            // Includes only "Beverages" rows from the "CategoryName" table to the Extract Data Source.
            dataExtract.ExtractSourceOptions.Filter = "[CategoryName] = 'Beverages'";
            // Limits displayed products from the "Beverages" category to "Chai".
            dataExtract.Filter = "[ProductName] = 'Chai'";
            dataExtract.UpdateExtractFile();
            // Adds the Extract Data Source to the dashboard. 
            dashboardDesigner.Dashboard.DataSources.Add(dataExtract);
        }
    }
}

Refer to the following topic for more information on how to build filter criteria: Expression Constants, Operators, and Functions.