Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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); }); });
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>
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?
Update: I receive this slightly different set of console errors when embedding without the filter, though the report renders properly:
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
8 | |
4 | |
2 | |
2 |
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
2 |