Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. 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:
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |