-
Notifications
You must be signed in to change notification settings - Fork 478
Slicers
As you may have read from the Embed Configuration Details page, you can change slicer selection when loading a report. Using slicers APIs, You can also get and set slicer state.
You may want to read Slicer Docs about how to use slicers in Power BI.
Slicer state contains the current filters applied by the slicer. Slicers support the following types of filters:
- Basic filters
- Basic filters with Keys.
- Advanced filters
- Relative date filters.
You can read more about creating filter object on Filters page.
type ISlicerFilter = IBasicFilter | IBasicFilterWithKeys | IAdvancedFilter | IRelativeDateFilter;
interface ISlicerState {
filters: ISlicerFilter[];
}To get a slicer state you need to find the slicer visual and call a method called getSlicerState on this visual.
visual.getSlicerState()
.then(state => {
...
});To set a slicer state you need to create a SlicerState object, find the slicer visual and call a method called setSlicerState with the slicer state you created.
visual.setSlicerState(state)
.catch(errors => {
// Handle error
});A slicer can be shown from one of various types:
This slicer shows a list, dropdown values (or other views), where you can select single or multiple items to filter the report accordingly.
To change a selection for these types of slicers you need to create a BasicFilter. example:
const basicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Store",
column: "Count"
},
operator: "In",
values: [1,2,3,4],
filterType: pbi.models.FilterType.BasicFilter
};
visual.setSlicerState({
filters: [basicFilter]
});Range slicers support conditions like: Between, Before, After, .. To change a selection for range slicers you need to create an AdvancedFilter. example:
const advancedFilter: pbi.models.IAdvancedFilter = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Store",
column: "Number"
},
logicalOperator: "And",
conditions: [
{
operator: "GreaterThanOrEqual",
value: 30
},
{
operator: "LessThan",
value: 40
}
],
filterType: pbi.models.FilterType.AdvancedFilter
};
visual.setSlicerState({
filters: [advancedFilter]
});Relative date slicers support conditions like: Last Week, Last 5 Years, ... To change a selection for Relative date slicers you need to create an AdvancedFilter. example: