2

I have a working app based on the App Owns Data documentation & Javascript sample:

https://learn.microsoft.com/en-us/power-bi/developer/embed-sample-for-customers

https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html#

I am able to get the data out of each visualisation but I also want to know what filters are affecting it.

I can get the slicer states, but cannot get any filters applied by clicking on the charts. If you click on one datapoint, that filters the entire page. In the dashboard I can then click on the filter icon next to each chart and see 'Filters and slicers affecting this visual'.

I would really like to get this information via the JS API, but can't find it in the page.getFilters(), report.getFilters() or visual.getFilters().

Is it possible to do, and how?

2
  • Try to take a look at information returned when you capture a bookmark (BookmarksManager.capture). I've never tried to parse it, but it could be useful for you. Commented Jun 11, 2021 at 15:09
  • That gives me a state which is an encoded string. I see no way to translate that into something I can work with. Commented Jun 14, 2021 at 9:59

1 Answer 1

2

For getting the filters applied on the visual, you can use the following:

async function get_visual_filters() {
  // Get all the pages of the report
  const pages = await report.getPages();

  // Find required page
  const page = pages.find((p) => p.name === "ReportSection1"); // The page in which visual is present

  // Get the required visual.
  const visuals = await page.getVisuals();

  // Find the visual using Guid
  const visual = visuals.find((v) => v.name === "VisualContainer1");

  // Retrieve the filter of visual:VisualContainer1
  const filters = await visual.getFilters();
  console.log("The filters applied on the visual are: ", filters);
}

To get the page level filters, you can use:

const pageFilters = await page.getFilters();

To get the report level filters, you can use:

const reportFilters = await report.getFilters();

Output: [1]: https://i.sstatic.net/O5q6d.png

Please refer following links:

  1. https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/get-visuals
  2. https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-filters
  3. https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-filters#get-filters
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. However, the visual.getFilters does not get filters applied by clicking on other visuals

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.