Improve report performance by using filters
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
Reports that return large data sets can be difficult to use and can cause performance problems. To limit the data that is presented in a report, use data filters.
In addition to data filtering supported by Reporting Services, Microsoft Dynamics 365 supports data pre–filtering. You can use data pre-filtering to:
Make reports context-sensitive by narrowing the scope of a report to return more relevant data.
Retrieve and display a result set faster because only more relevant data is returned.
Allow the report to be filtered using the Advanced Find feature.
Important
Currently, report queries with hierarchical operators, such as the Under operator, can’t be used with report filtering. When you try to run a report that uses a hierarchical operator, the report won’t render.
In this topic
Enabling data pre-filtering in Fetch-based reports
Enabling data pre-filtering in SQL-based reports (Dynamics 365 on-premises only)
Passing filters in the filter summary
Default filters
Enabling data pre-filtering in Fetch-based reports
Fetch-based reports support only automatic data pre-filtering. A report can have multiple data sets and multiple FetchXML queries. One data set supports one FetchXML query. To enable pre-filtering for the primary or linked entity in a Fetch-based report, you must set the value of the enableprefiltering parameter to “1”, and specify a parameter name in the prefilterparametername property. The parameter name should start with “CRM_” to specify it as a hidden parameter. As with the Microsoft SQL Server-based report, this parameter specified in the FetchXML query acts as a sub query within the FetchXML query, and the sub query is constructed with the value specified by the user in the Advanced Find area while running a report.
The following example displays how to enable pre-filtering for the primary entity in the FetchXML query.
<CommandText
<fetch distinct="false" mapping="logical">
<entity name="account" enableprefiltering="1" prefilterparametername="CRM_FilteredAccount">
<attribute name="name" />
<attribute name="accountid" />
</entity>
</fetch>
</CommandText>
<DataSourceName>CRM</DataSourceName>
Similarly, you can enable pre-filtering for the linked entity. You can also specify a different pre-filtering condition for the linked entity in the FetchXML query by specify a different and unique name for the parameter name in the prefilterparametername property.
If you are manually modifying a Fetch-based report definition without using the Report Wizard in the Microsoft Dynamics 365 web application or SQL Server Data Tools to enable pre-filtering for primary and linked entities, make sure that you:
Similarly, you can enable pre-filtering for the linked entity. You can also specify a different pre-filtering condition for the linked entity in the FetchXML query by specify a different and unique name for the parameter name in the prefilterparametername property.
If you are manually modifying a Fetch-based report definition without using the Report Wizard in the Microsoft Dynamics 365 web application or SQL Server Data Tools to enable pre-filtering for primary and linked entities, make sure that you:
<fetch distinct="false" mapping="logical"> <entity name="account" enableprefiltering="1" prefilterparametername="CRM_FilteredAccount">
Create a corresponding query parameter with the same name as specified for the prefilterparametername property. Make sure that the parameter name starts with CRM_ to specify it as a hidden parameter.
<QueryParameters> <QueryParameter Name="CRM_FilteredAccount"> <Value>=Parameters!CRM_FilteredAccount.Value</Value> </QueryParameter>
Create a corresponding report parameter with the same name.
<ReportParameters> <ReportParameter Name="CRM_FilteredAccount"> <DataType>String</DataType> <Prompt>CRM Filtered Account</Prompt> </ReportParameter> </ReportParameters>
Enabling data pre-filtering in SQL-based reports (Dynamics 365 on-premises only)
There are two ways that you can enable data pre-filtering on Microsoft Dynamics 365SQL-based reports: automatic and explicit.
Automatic pre-filtering
Automatic data pre-filtering is suited for simple queries. To enable automatic data pre-filtering on a report, you can use aliases for entity tables in queries. You do this by using an alias name that starts with CRMAF_.
For example, the following table shows a simple query modified to enable pre-filtering on the Account entity.
Query without pre-filtering |
Modified query with automatic pre-filtering enabled |
|||||
---|---|---|---|---|---|---|
```sql
SELECT
When you enable automatic data pre-filtering functionality by using the CRMAF_ prefix, Microsoft Dynamics 365 modifies the query to include a parameter (for example, P1) when it is uploaded to Microsoft Dynamics 365, as shown in the following table.
|