I am working on embedding power BI reports on of my custom sites. I am able to embed report in my site. But now I need to implement reset filter which present in Power BI web site. As shown in below screen shot.
The only expectation is after click reset button in my site, It should clear or reset filters & slicer to original values.
I tried with
report.removeFilters();
But it just remove all Page filters. I don't want to remove all filter I want to reset them to default values. Also I want to reset slicer to default original values within report.
Any help is appreciated.
As of now, there is no possible way to do this using filters. Below is the alternative you could follow using bookmarks.
Bookmarks will help you to capture current state (filters,slicers,etc ) of the report.
Create a bookmark with default filters that you want in Power BI Service or Power BI Desktop.
Please follow below code snippets to retrieve the bookmark and apply it whenever you want to reset the filters -
a. Get a reference to the HTML
element that contains the embedded report:
const embedContainer = $('#embedContainer')[0];
b. Embed the report
:
const report = powerbi.embed(embedContainer, embedConfig);
c. Get the list of bookmarks of your report
const bookmarks = await report.bookmarksManager.getBookmarks();
d. Loop through the list and check for the appropriate bookmark.displayName that you want to apply
bookmarks.forEach(function (bookmark) {
if( bookmark.displayName.equals( ``Your expected bookmark`` ) ){
await report.bookmarksManager.apply(bookmark.name);
console.log("Applied bookmark - " + bookmark.name + ", with display name - "
+ bookmark.displayName);
}
});
Please refer the following - https://learn.microsoft.com/javascript/api/overview/powerbi/report-bookmarks