Events
Power BI DataViz World Championships
14 Feb, 4 pm - 31 Mar, 4 pm
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The Identity filter API allows you to create a visual that can filter categorical data using a semantic query.
It filters the data by data points rather than mathematical expressions.
The API keeps track of user selections and which data points to display. The data points are saved in an array and referenced by their position in the array.
This API is useful in the following scenarios:
Note
The Identity filter API is available from API version 5.1 To find out which version you’re using, check the apiVersion
in the pbiviz.json file.
The Identity filter model is based on the IIdentityFilter interface.
private filter: IIdentityFilter = {
$schema: “”,
filterType: FilterType.Identity,
operator: "In",
target: []
}
For example, if the visual received the following data view update:
The array is of type number[] and it contains the identity fields of the items that the user selected.
The identityIndex corresponds to the index of the value in the semantic model's value array (see the following example).
In the above example: {identityIndex: 0} = "Aaliyah" {identityIndex: 1} = "Aaliyah" {identityIndex: 02 = "Aaliyah" etc.
To use the Identity filter API, your powerbi-models version needs to be 1.9.1 or higher.
Add the following property as a member of the visual.ts class:
private filter: IIdentityFilter = {
$schema: “”,
filterType: FilterType.Identity,
operator: "In",
target: []
}
To handle Power BI updates, read the target array from the 'jsonFilters' in the 'VisualUpdateOptions' and translate it to the corresponding values. These values are the ones that were selected. In the previous example, a target array of [0,10] corresponds to the values of Aliyah and Abigail.
To handle user selections in the previous example, click on the first Abigail to add the value 8 to the filter target array and send it using the following command:
this.visualHost.applyJsonFilter(this.filter, "general", "filter", powerbi.FilterAction.merge);
Starting from API 5.1.0, to support the identity filter on visuals that were created using a version earlier than 2.2, add the following lines to your capabilities.json file:
"migration": {
"filter": {
"shouldUseIdentityFilter": true
}
}
These lines convert the selections to identity filters.
Note
This step is only necessary for existing visuals created with older APIs. Newer visuals don't need to add this.
Use Power BI visuals selections to add interactivity to a visual
More questions? Try the Power BI Community.
Events
Power BI DataViz World Championships
14 Feb, 4 pm - 31 Mar, 4 pm
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreTraining
Module
Configure Power BI report filters - Training
Report filtering is a complex topic because many techniques are available for filtering a Microsoft Power BI report. However, with complexity comes control, allowing you to design reports that meet requirements and expectations.
Certification
Microsoft Certified: Power BI Data Analyst Associate - Certifications
Demonstrate methods and best practices that align with business and technical requirements for modeling, visualizing, and analyzing data with Microsoft Power BI.
Documentation
The Visual Filters API for better embedded BI insights - Power BI
This article discusses how Power BI visuals can filter other visuals. Enable better embedded BI insights using Power BI embedded analytics.
The Filter applied API in Power BI custom visuals - Power BI
This article describes the API parameter that indicates whether or not a filter is applied to a visual.
Subselection API in Power BI Visuals - Power BI
The article describes how to use Power BI Visuals subselectionAPI to allow users to format visuals easily.