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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ats1958
Helper II
Helper II

Power BI Embedded + Javascript API Report Not Rendering

I'm attempting to extend Power BI's "App Owns Data" example to use some Javascript filtering. The code I've added is below. I'm getting a critical Javascript syntax error on line 86, which is the blank line following "filters.push(Filter1);"

 

var Filter1 = {    $schema: "http://powerbi.com/product/schema#advanced",    target: {        table: "PBI Load",        column: "Business Unit"
    },    logicalOperator: "OR",    conditions: [
        {
            operator: "Contains",            value: "Information"
        }
    ]
}report.on('loaded', event => {    report.getFilters()
        .then(filters => {            filters.push(Filter1);

            return report.setFilters(filters);
        });
});
6 REPLIES 6
DileepRajam
Frequent Visitor

do anyone know what is the new links for below

<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>

<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>
Eric_Zhang
Microsoft Employee
Microsoft Employee

@ats1958

The post Javascript portion seems good, I don't find any syntax error by using some syntax checker. Could you post all the javascript code?

 

By the way, you don't have to set filter after report loaded. You can set filter in the report embed configuration. See below demo.

 

 

<html>

 <script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>

<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"></script>
 
<script type="text/javascript">
window.onload = function () {  
var Filter1 = { $schema: "http://powerbi.com/product/schema#advanced", target: { table: "DateTable", column: "Date" }, logicalOperator: "And", conditions: [{ operator: "LessThandOrEqual", value: "2017-02-20 00:00:00" }, { operator: "GreaterThanOrEqual", value: "2017-01-12 00:00:00" } ] } var clientname = ["powerbi"]; // Read embed application token from Model var accessToken = "H4sIAAAAxxxxxx"; // Read embed URL from Model var embedUrl = "https://app.powerbi.com/reportEmbed?reportId=1685axxxxxxxdf3861&groupId=dc581184-a209-xxxxxxx6b6c15"; // Read report Id from Model var embedReportId = "1685a4xxxxxx1df3861"; // Get models. models contains enums that can be used. var models = window['powerbi-client'].models; // Embed configuration used to describe the what and how to embed. // This object is used when calling powerbi.embed. // This also includes settings and options such as filters. // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details. var embedConfiguration = { type: 'report', tokenType: models.TokenType.Embed, accessToken: accessToken, embedUrl: embedUrl, id: embedReportId, permissions: models.Permissions.All, filters:[Filter1], settings: { //filterPaneEnabled: true, navContentPaneEnabled: true } }; var $reportContainer = $('#reportContainer'); var report = powerbi.embed($reportContainer.get(0), embedConfiguration); /** report.on('loaded', event => { report.getFilters() .then(filters => { filters.push(Filter23); return report.setFilters(Filter23); }); }); **/ } </script> <div id="reportContainer" powerbi-settings-nav-content-pane-enabled="true" powerbi-settings-filter-pane-enabled="true"></div> </html>

 

I have attempted to implement that below and the report doesn't render now. The iFrame and Power BI loading screen appear.

 

@model PowerBIEmbedded_AppOwnsData.Models.EmbedConfig

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"></script>  
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js" "></script>

@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
    <div id="errorWrapper">
        <h2>
            Error
        </h2>
        @Model.ErrorMessage
    </div>

    return;
}

<h2>Embedded Report</h2>
<div id="reportContainer"></div>
<script>
    // Read embed application token from Model
    var accessToken = "@Model.EmbedToken.Token";

    // Read embed URL from Model
    var embedUrl = "@Html.Raw(Model.EmbedUrl)";

    // Read report Id from Model
    var embedReportId = "@Model.Id";

    // Get models. models contains enums that can be used.
    var models = window['powerbi-client'].models;

    var Filter1 = {
        $schema: "http://powerbi.com/product/schema#advanced",
        target: {
            table: "PBI Load",
            column: "Annualized Base"
        },
        operator: "GreaterThanOrEqual",
        value: "150000"
    }


    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    var config = {
        type: 'report',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
        id: embedReportId,
        permissions: models.Permissions.All,
        filters: [Filter1],
        settings: {
            filterPaneEnabled: false,
            navContentPaneEnabled: true
        }
    };

    // Get a reference to the embedded report HTML element
    var reportContainer = $('#reportContainer')[0];

    // Embed the report and display it within the div container.
    var report = powerbi.embed(reportContainer, config);



    

</script>

 

 

I have just noticed the following on the console when loading. Does this have to do with the accessToken? Are there additional changes needed when going from AppOwnsData sample to using the JavascriptAPI?

pbi-embedded-error.JPG

Update: I receive this slightly different set of console errors when embedding without the filter, though the report renders properly:

console-pbi.JPG

@Eric_Zhang Do you have any other thoughts on this?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.