microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
309 stars 98 forks source link

Set filters for power bi embeded report #67

Closed JinaliWijetunge closed 1 year ago

JinaliWijetunge commented 2 years ago

My question is about how to embed a power bi report with a basic filter. <PowerBIEmbed embedConfig={{

    type: "report",
    tokenType: models.TokenType.Embed,
    filters: [{$schema:  "http://powerbi.com/product/schema#basic",

                  target: {
                    table: "User",
                    column : "name"

                  },
                  operator:"In",
                  values:[ "XYZ"],
                  filterType: models.FilterType.Basic,
                }],
}}

/>

Here type of property filter in IEmbedConfiguration is filters?: models.IFilter[]; but based on my requirement, this should be IReportLoadConfiguration where filters?: ReportLevelFilters[]

How am I supposed to add this configuration

rad10wave commented 1 year ago

You can use IReportEmbedConfiguration to add filters, then you can add the filters like:

reportConfig: IReportEmbedConfiguration = {
        type: 'report',
        embedUrl: EMBED_URL,
        tokenType: models.TokenType.Embed,
        accessToken: ACCESS_TOKEN,
        settings: undefined,
        filters: [{
            $schema: "http://powerbi.com/product/schema#basic",
            filterType: models.FilterType.Basic,
            target: {
                table: "Geo",
                column: "Region"
            },
            operator: "In",
            values: ["West", "Central"]
        }],
    }

please let us know if you have any further questions

elgabato commented 1 year ago

Can I do like this? filters: [{ $schema: "http://powerbi.com/product/schema#basic", filterType: models.FilterType.Basic, target: { table: "Geo", column: "Region" }, operator: "In", values: ["West", "Central"] }],

    filters: [{
        $schema: "http://powerbi.com/product/schema#basic",
        filterType: models.FilterType.Basic,
        target: {
            table: "Geo",
            column: "City"
        },
        operator: "In",
        values: ["test1", "City"]
    }],

doing a filter on a single table but different columns.

KotanaSai21 commented 1 year ago

@elgabato , Yes, We can apply filter on single table but different columns. Refer to my sample code as below.

// Create the filter object. For more information see https://go.microsoft.com/fwlink/?linkid=2153364
const filter = {
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "Geo",
        column: "Region"
    },
    operator: "In",
    values: ["West", "Central"]
};

// Create the filter object. For more information see https://go.microsoft.com/fwlink/?linkid=2153364
const filter1 = {
    $schema: "http://powerbi.com/product/schema#basic",
    target: {
        table: "Geo",
        column: "State"
    },
    operator: "In",
    values: ["AK"]
};

// Add the filter to the report's filters.
try {
    await report.updateFilters(models.FiltersOperations.Add, [filter1,filter]);
    console.log("Report filter was added.");
}
catch (errors) {
    console.log(errors);
}

For more information refer Control report filters. Feel Free to reach out for any other queries and you can also ask them here Power BI Embedded on Stack Overflow