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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.