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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
manashSahoo
Regular Visitor

GetSlicerState from a Custom Slicer

We use embedded Power BI.

 

I have built a custom date slicer.  We allow the user to save various slicer states and then recall them at a later time.  This works fine for the built-in slicers.  I have code that filters visuals from page.getVisuals where visual.type === "slicer".  I then save this.  However, the custom slicer is not included.  I am not surprised by this because I have no idea where to set the visual type.

 

In reference to the link below, in order to use get/set slicer state, I need the visual to be of type slicer.

https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-slicers#slicer-apis

 

I have searched endlessly but with no luck.  What in the PBIVIZ pipeline defines the control as a slicer?

 

Thank you

2 REPLIES 2
MAwwad
Solution Sage
Solution Sage

 

In order to use the get/set slicer state methods in the Power BI JavaScript API, the custom slicer needs to be defined as a visual of type "slicer". This is typically done by setting the "type" property of the visual when it is created.

If you are using the Power BI Embedded framework to create your custom slicer, you can set the visual type by passing the "type" property in the "visualSettings" parameter of the create method.

For example:

 

Copy code
let slicerSettings = { type: "slicer", slicer: { ... } }; let slicerVisual = powerbi.createVisual(element, slicerSettings);

 

 

Alternatively, you may set the type property with the setVisual method.

 

Copy code
let slicerVisual = powerbi.createVisual(element); slicerVisual.setVisual({ type: "slicer", slicer: { ... } });
 

Make sure that the visual type is set to "slicer" and after that you should be able to use the get/set slicer state methods with your custom slicer.

Please be aware that in order to use getSlicerState the slicer must be in the same page as the visuals that you would like to filter.

Thank you for your response.  

 

If you look at this sample source code for a sample slicer, I don't see where the type is being set.  I would expect to set the type in the contructor, perhaps.

 

Though we are using the embedded framework, we are loading reports from the Power BI Service.  The reports are built using the PBI Desktop where the custom slicer is added, then published to our workspace on PBI.  Then, our web application with the Embedded Framework loads a selected report into the frame.

 

If I have to set the type after the visuals are loaded, then I will need to find the visual from the active page.  The visual's names look like a shorter version of a guid.

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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