Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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
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:
Alternatively, you may set the type property with the setVisual method.
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.
User | Count |
---|---|
40 | |
32 | |
30 | |
25 | |
24 |
User | Count |
---|---|
53 | |
53 | |
35 | |
31 | |
28 |