Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Dzvene
New Member

Filters target doesn't match slicer target (Hierarchy Slicer, Embedded)

We are trying to save the state of the slicers and apply them.

We get the state using getSlicerState () and, on the onLoad event, we try to apply them with .setSlicerState(),

 

When we try to apply the saved state, we get an error:

Снимок экрана 2020-03-27 в 10.02.46.png

 

The state that we save and try to apply:

Снимок экрана 2020-03-27 в 10.06.43.png

Why we can't use the saved state for the same slicer аnd what do we need to do to apply them?

 

For other slicers, it works correctly, the problem only with Hierarchy Slicer.

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @Dzvene ,

Please try to provide a target of type IFilterHierarchyTarget. example:

const basicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    hierarchy: "Country",
    hierarchyLevel: "Code"
  },
  operator: "In",
  values: [456, 943],
  filterType: pbi.models.FilterType.BasicFilter
};

visual.setSlicerState({
    filters: [basicFilter]
});

Reference:

https://github.com/Microsoft/PowerBI-JavaScript/wiki/Slicers

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
shahabazshafisk
Regular Visitor

I tried the same format for the filter and I am still getting the same error.

const filters = {
    "target": { table: "Date", hierarchy: Date Hierarchy, "hierarchyLevel": "Date" },
    "filterType": models.FilterType.RelativeDate,
    "operator": models.RelativeDateOperators.InLast,
    "timeUnitsCount": 10,
    "timeUnitType": models.RelativeDateFilterTimeUnit.Days,
    "includeToday": true
};


The the SlicerState I got upon calling getSlicerState Method

{
"filters": [
{
"$schema": "http://powerbi.com/product/schema#relativeDate",
"target": {
"table": "date",
"hierarchy": "Date Hierarchy",
"hierarchyLevel": "Date"
},
"filterType": 4,
"operator": 0,
"timeUnitsCount": 6,
"timeUnitType": 4,
"includeToday": true
}
],
"targets": [
{
"table": "date",
"column": "Date"
}
]
}


v-xuding-msft
Community Support
Community Support

Hi @Dzvene ,

Please try to provide a target of type IFilterHierarchyTarget. example:

const basicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    hierarchy: "Country",
    hierarchyLevel: "Code"
  },
  operator: "In",
  values: [456, 943],
  filterType: pbi.models.FilterType.BasicFilter
};

visual.setSlicerState({
    filters: [basicFilter]
});

Reference:

https://github.com/Microsoft/PowerBI-JavaScript/wiki/Slicers

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors