Reputation: 790
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?
Upvotes: 2
Views: 3618
Reputation: 49
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:
Upvotes: 2