cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
guibovo
New Member

Power BI Embedded Tracking visual filters (slicers)

Hello, I would like to know if there is a way to track visual filters (slicers) that are being applied in my embedded reports.

 

If there is, could some one tell me if there is a documentation about that? 

 

Or if there is no documentantion about that, please, how could I do this?

 

Thank you.

1 ACCEPTED SOLUTION

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)
          })
        })
      });
    });
....

View solution in original post

5 REPLIES 5
dgpshiva
New Member

The "visual.getSlicerState()" throws "Visual container config is not initialized" error.
Which seems to be a known issue:

https://community.powerbi.com/t5/Issues/setSlicerState-javascript-method-does-not-work/idi-p/517624 
https://github.com/jongio/PowerBI-visuals-radioSlicer/issues/2 

Is there a workaround for this?

Jayendran
Solution Sage
Solution Sage

Hi @guibovo ,

 

I don't think there is such a capability to track the slicers which applied on the runtime.

 

You can post that in the Idea Forum https://ideas.powerbi.com/forums/265200-power-bi-ideas

 

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)
          })
        })
      });
    });
....

Hello @guibovo, i was facing same issue. Tried your approach but getSlicerState is not resolving when i checked "Select All" option in the slicer. Can you please suggest what i'm missing?

You can go one further and look at the table in the filters in the slicer states. I do this and grab all of the ones whose tables are 'DimDate'. Those are the date slicers.

Then I can set the value to any desired date via slicer.setSlicerState().

This enables me to use a bootstrap javascript date picker instead of the radio button slicer.

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors