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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Issue in setting slicer value using JavaScript API

Hello Experts,

We need your help in this.
We have various PowerBI reports that are used on several pages in Drupal based Website, each with slicers in the visualisations. We'd like to apply a slicer filter keyword using the JavaScript API, only if the slicer contains that given keyword.

We found that setting the slicer keyword when the keyword is not in the dropdown results in the keyword being added to the dropdown. To avoid this, we've tried checking if the filter is available in the dropdown before setting it. However after fetching the slicer filter values, it only returns the default value and not the others.
Here's a simplified version of the code we've got so far:

report.on('rendered', () => {
  report.getPages().then(pages => {
    const filter = {
      $schema: 'http://powerbi.com/product/schema#basic',
      target: {
        table: 'Organisation Source',
        column: 'Organisation Description'
      },
      operator: 'In',
      values: ['SLICER KEYWORD I WANT TO SET'],
    };
    pages.forEach(page => {
      page.getVisuals().then(visuals => {
        for (visual of visuals) {
          if (visual.type !== 'slicer') {
            continue;
          }
          visual.getSlicerState().then(state => {
            // state.filters.values === ['Statewide'] not ['Statewide', 'another option', ...']
            if (state.filters.values.includes('SLICER KEYWORD I WANT TO SET')) {
              visual.setSlicerState({
                filters: [filter]
              })
            }
          });
        }
      });
    });
  });
});

However note that after calling `visual.getSlicerState()`, `state.filters.values` only includes 1 (default) value, with no other dropdown values. How can I access the full list of slicer drop-down values, regardless of whether they're checked?

Thanks!

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Do you Apply filter in Javascript APIs in embedding scenarios?

If so, please post in Develop forums where people have more experience in Power BI Embed.

 

Based on my research, i find a useful article you may refer to

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

According to it :

Categorical slicers supports displaying a list, dropdown or cards of values, where you can select single or multiple items to filter the report accordingly.

To change a selection for these types of slicers you need to create an IBasicFilter object. example:

const basicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    column: "Count"
  },
  operator: "In",
  values: [1,2,3,4],
  filterType: pbi.models.FilterType.BasicFilter
};

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

 

Best Regards
Maggie

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

I don't think Maggie's reply answers this question

"However note that after calling `visual.getSlicerState()`, `state.filters.values` only includes 1 (default) value, with no other dropdown values. How can I access the full list of slicer drop-down values, regardless of whether they're checked?"

I have the same question.  How do I get a list of all the options for a slicer in an embedded PBI using the javascript api.  visual.getSlicerState() only lists the selected options.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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