Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Don-Bot
Resolver I
Resolver I

How do I export a report filter using C# XMLA Endpoint for Power BI Embedded?

I am working through setting up an export to pdf button for power bi embedded.  I have the initial export working where it will export the report in question.  However, if I click on a slicer or filter within a visual I am unable to export the filter used so I can then export the filtered report to pdf for the end users.  

 

So how can I get the filters a user has clicked on so that I can export that information?

Below is whatI have so far.  

 

 

public 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 client = GetPowerBiClient();
    var userName =WebHelper.GetCompanyID();
    var report = client.Reports.GetReportAsync(groupId, reportId).Result;
    // Get the filters from the report
    var reportTest = await client.Reports.GetReportInGroupAsync(groupId, reportId);  //placed these here to see if there were any values that exported report filters
    var reportTestAgain = client.Reports.GetReportAsync(groupId, reportId);  //placed these here to see if there were any values that exported report filters


    var reportName = report.Name;
    string ExportFilter = "";
    var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
    {

        Identities = new List<EffectiveIdentity>
        {
            new EffectiveIdentity
            {
                Username = userName.ToString(),
                Roles =new List<string> { "RLS_ROLE" },
                Datasets = new List<string> { report.DatasetId }
            }
},
        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(),

        //Pages = pageNames?.Select(pn => new ExportReportPage { PageName = "ReportSectionbb06cfc5609070ee41ea" }).ToList(),
        // ReportLevelFilters collection needs to be instantiated explicitly
        ReportLevelFilters = !string.IsNullOrEmpty(urlFilter) ? new List<ExportFilter>() { new ExportFilter(urlFilter) } : null  //no url filter comes through, I do not see any ?filter in the URLs

    };

    var exportRequest = new ExportReportRequest
    {
        Format = format,
        PowerBIReportConfiguration = powerBIReportExportConfiguration
    };
    if (ExportFilter != "")
    {
        exportRequest.PowerBIReportConfiguration.ReportLevelFilters =
          new List<ExportFilter>() {
    new ExportFilter { Filter = ExportFilter }
          };
    }

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Don-Bot,

Did you mean the filters that applied on the 'read view' mode instead of saved to your report?
AFAIK, current the export file API only check saved filters. The 'read view' mode operations did not really apply to the report side so they can't be recognized and traced by rest API.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Don-Bot,

Did you mean the filters that applied on the 'read view' mode instead of saved to your report?
AFAIK, current the export file API only check saved filters. The 'read view' mode operations did not really apply to the report side so they can't be recognized and traced by rest API.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Solution Authors