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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Don-Bot
Helper I
Helper 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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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