Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Can we add report level filter in power bi visuals from code (JavaScript)
@v-vaaga wrote:
Can we add report level filter in power bi visuals from code (JavaScript)
Yes.
You can check the JavaScript wiki Filters.
Here's a simple demo to practise.
<html>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/bower_components/powerbi-client/dist/powerbi.js"></script>
<script src="https://microsoft.github.io/PowerBI-JavaScript/demo/bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript">
window.onload = function () {
var Filter = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "table Name",
column: "column Name"
},
logicalOperator: "OR",
conditions: [
{
operator: "Contains",
value: "CN"
},
{
operator: "Contains",
value: "CO"
}
]
}
var embedConfiguration = {
type: 'report',
accessToken: 'eyJ..YourTokenHere..w',
id: 'report ID',
embedUrl: 'yourEmbedUrlHere',
};
var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
report.on('loaded', event => {
report.getFilters()
.then(filters => {
filters.push(Filter);
return report.setFilters(filters);
});
});
}
</script>
<div id="reportContainer" powerbi-settings-nav-content-pane-enabled="true" powerbi-settings-filter-pane-enabled="true"></div>
</html>
Hi @Eric_Zhang,
I tried your solution but when my application try to load report, it shows "The Content is not available", But when I load report using @Html.PowerBIReportFor(m => m.Report, new { id = "pbi-report", style = "height:85vh", powerbi_access_token = Model.AccessToken }) with filter, It getting loadded.
Is I am doing something wrong?
Pleae help
@bhanupowerbi wrote:
Hi @Eric_Zhang,
I tried your solution but when my application try to load report, it shows "The Content is not available@", But when I load report using @Html.PowerBIReportFor(m => m.Report, new { id = "pbi-report", style = "height:85vh", powerbi_access_token = Model.AccessToken }) with filter, It getting loadded.
Is I am doing something wrong?
Pleae help
"The Content is not available" is usually due to an invalid token. What do you get from the network traffic in a dev tool(F12 in Chrome).
Thanks. This approach works fine if we are embedding PowerBI visuals into our html or aspx page.
But my requirement is to make it work in online PowerBI (msit.powerbi.com/groups/Some-Report-GUID). I have my custom visual and its corresponding JS. So there I need to add report level filter from code (JavaScript) i.e., without dragging and dropping that filter column.
Not to my knowledge.
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 |
| User | Count |
|---|---|
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |