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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Grasmachien
Frequent Visitor

How to get slicer options with PowerBI client

Background

Currently we have an embedded PowerBI iframe with the PowerBi client.

This iframe contains some dropdowns to filter the data.

 

Question

I'm looking for a way to remove some slicers/filters from the embedded iframe which the PowerBi client creates and create custom filters which update the iframe.

What I have tried
I'm able to find the slicers with the "getVisuals" function.
But I am unable to find the available options.
When using "getFilters" on this slicer i see an empty array called "values".
I assume this is where the active options are stored, but even after selecting some values in the dropdown the array still stays empy.

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Grasmachien ,

Please review the following links, hope they can help you.

Power BI Embedded Tracking visual filters (slicers)

I have found a way to do that, not as beatiful as I want, but still a nice solution.

 

To those who are interested in this same case scenario, I have used PowerBI Javascript API, and with this API  to get all pages (report.getPages()) and run it to find the active page (page.isActive), then I get all visuals (page.getVisuals()) and filter it by slicers (visual.type === 'slicer'), by there I get a list of all slicers in my page, to get values of filtered slicers I simply check if the slicer has filters (it is an array), and if it do, I add to an array to save it later.

 

Long story short :

User PowerBI Javascript API -> get all pages of report -> get active page -> get all visuals in page -> filter by slicer -> get all slicers that have been filtered -> get slicer state to know what have been done to this filter -> do whatever you need with it.

 

const isSlicer = visual => visual.type === 'slicer';

const isPageActive = page => page.isActive;

...
  let embeddedReport = powerbi.embed(dashboardContainer, config);
  embeddedReport.on('rendered', function (event) {
    embeddedReport.getPages().then(pages => {
      activePage = pages.filter(isPageActive)[0];
      activePage.getVisuals().then(visuals => {
        slicers = visuals.filter(isSlicer);
        filteredSlicers = [];
        slicers.forEach(async slicer => {
          slicer.getSlicerState().then(slicerState => {
            if(slicerState.filters.length > 0) filteredSlicers.push(slicerState)
          })
        })
      });
    });
....

Control report slicers

Best Regards

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

Hi @v-yiruan-msft,

 

Thanks for your answer!

This explanation only shows the current applied filters.
Is there a way to get all the possible options (applied and non applied) that are available for a specific slicer?
For example: We have 3 slicers as dropdowns in our embedded report. The values of the these slicers are dependend on the main filter that is beind set on the report. So they are not always the same.
Is there a way to get all the options that these slicers display so that I can rerender them outside of the iframe in custom html/css?

@GrasmachienThis is possible using the `VisualDescriptor.exportData()` method, which gives you a list of up to 30,000 options.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.