Forum Discussion
Export to file - Power BI Report with Filters / Parameters
- Anonymous6 years ago
Hi Anonymous
The documentation currently states that the Bookmark name (whilst accepted as a parameter) is not currently available.
https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofile#pagebookmark
The only way to update output via bookmarks, is to pass in the bookmark state.
And the only way that you can get the bookmark state (that I know of) is via the JavaScript API. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Bookmarks#capture-and-get-a-current-view-as-a-bookmark-object-and-apply-it-back-on-the-current-session
The 'capture' function will return a single string value that represents the bookmark state. You can then pass this into the API.
This is far from ideal... but I think the export API endpoint is still under preview, so will likely change quite a bit.
The idea I raised for adding missing functionality to this API has also moved into the planned phase. So hopefully, it won't be too long before these missing features are available. https://ideas.powerbi.com/ideas/idea/?ideaid=0e056f7d-34b4-4778-974f-929228effcdd
Cheers, Matt
I feel your pain Matt! I just spent 3 days writing code to use the API to export a report to PNG. I just got to the filtering bit - we need to create a separate image for each filter value - and have hit a brick wall. Did you find a workaround?
- Anonymous6 years agoNot applicable
Hi latearrival
No workaround that I know of.
Depending on how many filters you have and what your model looks like, you might be able to use the Bookmarks feature?
I attempted to work out if we could generate bookmark state at runtime, then apply it to a PDF/PNG export, but this was a non-starter.
Looking at the idea site though... looks as though this has progressed to 'Under Review'.
So I guess we will have to wait.- latearrival6 years agoAdvocate I
Hi Anonymous
Yeah, I see that bookmarks is a workaround, albeit a poor one. The whole point of using the Export endpoint is to automate. And creating bookmarks is a manual process.
I'm very very new to Power BI so I can't get my head around this yet, but this article hints at being able to fudge Roles (handing in a fake user ID as a query string parameter when the access token is requested?) and using a permissions table to drive Row Level Security. So, to use the Export endpoint to produce a sales report for, let's say, a given product, I'm wondering if I could hand in a product code as the fake user ID and then... (I'm not sure what happens then 🙂 ).
- latearrival6 years agoAdvocate I
Hey Anonymous, I'm going to see if I can use Bookmarks until filters are supported. I see in the Export to File doco that you can pass in a PageBookmark specifying "The bookmark to apply on a single page. Provide name or state, but not both", but that the bookmark name is currently not supported. Do you know how I can find out the "state" value for a given bookmark?
- Anonymous6 years agoNot applicable
I went looking at options for this... The only oneI can find (the one I was previously experimenting with) was via the JavaScript embedding API. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Bookmarks
The section at the end shows how to capture a bookmark programatically. The resulting object then holds the bookmark state.// Capture the current view let capturedBookmark = report.bookmarksManager.capture(); // Applied previously captured state report.bookmarksManager.applyState(capturedBookmark.state);I tried to work out how this state object was structured, in the hope I could dynamically create it in C#... but I didn't get very far.
As I mentioned before... If you only have a small number of filters and bookmark states that you need to capture, then you could use this method to fetch those states and reuse them as many times as you like. But as soon as you want to do anything really dynamic... you hit a bit of a blocker.
I am keeping my fingers crossed for quick updates to the API to add the parameters. 😀