cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Responsive Resident
Responsive Resident

Export to file - Power BI Report with Filters / Parameters

HI All,

I am looking at the new (currently in preview) API for exporting Power BI reports as images/pdf files.
https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofileingroup 

There currently isn't a way to specify Filter/Slicer values for Power BI Reports!
This feels like a big omission to me, especially considering the inclusion of Bookmark capabilities.

Is there a published roadmap for this API endpoint anywhere AND/OR does anyone know if we can expect to see filter options anytime soon?

The API is unusable for many scenarios without this.
I am keeping my fingers crossed that it arrives soon.

Cheers,
Matt

1 ACCEPTED SOLUTION

Hi @vmakhija 

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-b... 

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

View solution in original post

18 REPLIES 18
Helper II
Helper II

Hi @orygreg2@MattCalderwood,

Here's a solution. BI Helper bihelper.tech automates the generation of  PDF / PPTX reports from Power BI (Pro and Premium), with slicers and filters applied either in batch mode or at runtime. Our implementation bypasses the limitations of the Power BI API endpoints. 

In BI Helper, you can select pages to print, schedule and generate multi-page PDF / PPTX reports and email them to your users. Our users routinely run hundreds of reports of up to 30 pages each, with the process fully automated from report generation to delivery. 

BI Helper is simple to configure and use with your Power BI reports and dashboards. It is secure and scalable and we offer a 14 day free trial. Test it out and let us know how it works. 

Kiran Hosakote

BI Helper

Helper II
Helper II

Hi @MattCalderwood,

 

We have an independent solution to the PDF export problem. We've built a tool called BI Helper https://bihelper.tech/ to automate the generation of  PDF / PPTX reports from Power BI (Pro and Premium), with slicers and filters applied. Our implementation bypasses the limitations of the API endpoints. 

With BI Helper, you can select report pages to print, schedule and generate multi-page PDF / PPTX reports and email them to your users. BI Helper has an option to include matrix and table visuals as Excel files, and lots of other advanced features. Our users routinely run hundreds of reports of up to 30 pages each, with the process fully automated from report generation to delivery. 


BI Helper is simple to configure and use with your Power BI reports and dashboards. It is secure and scalable and offers a 14 day free trial. Try it out and let us know how it works for you. 

 

Kiran Hosakote

BI Helper

New Member

Hey, 

 

@MattCalderwood , did you solve your issue? 
Workaround: Adding a dimension table to the row level security feature (the dimension you would like to filter on), and then filtering using the identities paramenter and then just looping on that should solve the issue.  🙂

Helper I
Helper I

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?

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.

Hey @MattCalderwood, 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?

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. 😀



Looks like the Idea has moved to 'Under Review'.
https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/40060261-add-filter-options-to-th...


I will update this thread as things progress.
Feel free to go and up-vote! 😀

@MattCalderwood 

@latearrival 

I am using the REST APIs for ExportToFile in my Power Automate flow.

I can export the PDF with no issues in a normal use case, but next I want to try out exporting a PDF with a particular bookmark.

Use case is - I have 5 user groups and I will create 5 bookmarks (one for each).

Will send the PDF in an email to each of them as per their individual bookmarks.

 

However, when I try to put the bookmark name in my flow, it doesn't work.

Here is how my flow looks -

vmakhija_0-1596722370342.png

 

The error I get is -

{
  "error": {
    "code""BadRequest",
    "message""Bad Request",
    "details": [
      {
        "message""Error converting value \"Group1_bookmark\" to type 'Microsoft.PowerBI.ServiceContracts.Api.V1.PageBookmark'. Path 'powerBIReportConfiguration.defaultBookmark', line 1, position 74.",
        "target""request.powerBIReportConfiguration.defaultBookmark"
      }
    ]
  }
}
 
Appreciate if you can provide any inputs in case you have any ideas around this use case?
 
Regards

Hi @vmakhija 

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-b... 

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

View solution in original post

Hi,

I'm posting here because I don't know if there has been an update to the docs since the original post was made.
I also have a requirement where I would like to call "ExportTo" using the REST API from a Javascript AJAX request.
In the docs (https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofile) it says that request body accepts powerBIReportConfiguration which in turn accepts a reportLevelFilters which is of type ExportFilter.
According the docs an ExportFilter is a string in the format as described under the article https://docs.microsoft.com/en-us/power-bi/collaborate-share/service-url-filters
 e.g.

?filter=Store/Territory eq 'NC'

I've tried various permutations trying to get this to work but I never get a filter applied.
Does anyone know...

- Should this filter actually be working now?
- What format the filter should be
- An example of it in code

Here's an example of an attempt that DOESNT work for reference:

 

var url = "https://api.powerbi.com/v1.0/myorg/reports/" + reportId + "/ExportTo";
$.ajax({
"type": "POST",
"url": url,
"headers": {
"Authorization": "Bearer " + accessToken
},
"data": {
"format": "pdf",
"powerBIReportConfiguration": {
"reportLevelFilters": [{ "filter": "products/ProductName eq 'ExampleProductName'" }]
}
}
})

Cheers,

Craig

Hi @craigbenstock  -  Any chance you've figured this out??  I'm in the same boat - wanting to apply a filter at runtime when exporting the report as PDF.  I haven't been able to find a working example.

Thanks, Greg

Hi @craigbenstock ,

Hope this helps you/somebody.  Kept digging and finally have a working copy - this is from a PowerShell script - so it has the double-quotes preceded by a qualifier:

$body = "{ format : `"PDF`",
powerBIReportConfiguration : { reportLevelFilters : [{ filter : `"TableName/FieldName eq 'SomeValue'`" }]} }"

. . .which looks same/similar to your version.

I used the "Try It" option from the MS documentation page to tweak the body formatting until I got a 20x response code:

https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofileingroup

And here's the page documenting that filtering is possible - it's too bad they don't provide a full, soup-to-nuts working copy that includes a filter example:

https://docs.microsoft.com/en-us/power-bi/developer/embedded/export-to#filters

 

I am running into the same issue as @craigbenstock but only since December it seems - but it's weird since exporting to .pdf/.pptx seems to work fine in the Power BI Service, just it's no longer capturing filters/bookmark state over API calls - any ideas?

@MattCalderwood 

Thanks for providing the details which I didn't know about.

 

Hoping that this functionality is added soon.

 

I have voted the idea.

 

Regards

Yeah, thanks Matt. I abandoned the bookmark path - too manual.

EDIT - I've now got it working with Identities and Roles. I can now export a report for every value of a filter.

In case this helps anyone else, here's my simple use case....

I want to create a report for every value of a filter called Country. Because filters aren't yet supported by the ExportTo API, I've used Roles instead.

I created a Role in Power BI Desktop called Country. The filter for this Role is on a table called countries, with a filter expression, [country_code] = username().  The countries table is already setup in my Model with the relevant relationships, and with cross filter direction = single. I then republished my report.

To get the ExportTo working for a specific country, I pass a country code through as the username in the body of the ExportTo API call:

 

{ "format":"PNG",
"powerBIReportConfiguration":
{ "identities": [
{ "username": "AUS",
"roles": [ "Country"],
"datasets": [ "XXXXXXXXXXXXXXX etc" ]
} ] } }

 

In my server-side code, all I need to do is call the ExportTo API in a loop, replacing the username in the body of the call with each country code.

Hi @MattCalderwood 

 

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 🙂 ).

 

 

Responsive Resident
Responsive Resident

I am struggling to find any details of 'future changes' or roadmap details for this API, so I created an idea for the inclusion of filter parameters.

https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/40060261-add-filter-options-to-th...

If you think that this functionality is missing - please go and upvote!
Thanks.

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.