0
votes

We integrated the PowerBI report in our web application using Power BI Rest API and embedded that report using the ReactJS library.

We have a new requirement to export the report in PDF and PPTX.

Scenario 1: If the user selects a certain area in a page and in the downloaded report it should only highlight data in PDF/PPTX.

This is working when I downloaded it from the app.powerbi.com portal but how we can achieve programmatically?

Question: How to get the current selection of area from a page using C# Power BI Rest API?

Scenario 2: If the report has more than one page and the user wants the only a certain page to download with either current selection/default values

Question: How to get and pass current page / all with current selection/default values using C# Power BI Rest API

1
If my answer remains the solution that you use, feel free to accept it by clicking the checkmark next to the answer so future readers will know how you solved your problem. - KarthikBhyresh-MT
@KarthikBhyresh-MT - The solution that you provided is not meet my requirement - nuthanmurari
@nuthanmurari did you get your requirement working. I also have same requirement, can you share your code or implementations - Sanjeev Gautam
No @SanjeevGautam - nuthanmurari

1 Answers

0
votes

Export Power BI reports to PDF, PPTX or PNG files using REST API is in preview now

Note that both the report and the dataset of the report you are exporting must reside on a premium or embedded capacity. Other preview limitations are detailed in the Export report to file article.

Please also be aware that as all new Power BI APIs, the Export-To-File API is included only in the Power BI APIs .NET SDK v3.

You can find here in official doc all the information required to use Power BI REST APIs to Export To File

Scenario 2: use parameter ExportReportPage

Scenario 1: Using reportLevelFilters in PowerBIReportExportConfiguration, you can export a report in a filtered condition. To export a filtered report, insert the URL query string parameters you want to use as your filter, to ExportFilter. When you enter the string, you must remove the ?filter= part of the URL query parameter.

here is the code example for Export request: End-to-end example

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

Please refer to embedded links

Example, an export request is sent for a specific page.

private async Task<string> PostExportRequest(
    Guid reportId,
    Guid groupId,
    FileFormat format,
    IList<string> pageNames = null, /* Get the page names from the GetPages REST API */
    string urlFilter = null)
{
    var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
    {
        Settings = new ExportReportSettings
        {
            Locale = "en-us",
        },
        // Note that page names differ from the page display names
        // To get the page names use the GetPages REST API
        Pages = pageNames?.Select(pn => new ExportReportPage(Name = pn)).ToList(),
        // ReportLevelFilters collection needs to be instantiated explicitly
        ReportLevelFilters = !string.IsNullOrEmpty(urlFilter) ? new List<ExportFilter>() { new ExportFilter(urlFilter) } : null,

    };

    var exportRequest = new ExportReportRequest
    {
        Format = format,
        PowerBIReportConfiguration = powerBIReportExportConfiguration,
    };

    // The 'Client' object is an instance of the Power BI .NET SDK
    var export = await Client.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest);

    // Save the export ID, you'll need it for polling and getting the exported file
    return export.Id;
}