cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shaunwilks Member
Member

API and Javascript filtering

We have an ASP.Net website that displays a powerBI report via “user owns data”…we have a local SQL Server using the On Premise Gateway and "Import Reports, not an Azure database.

 

In the C# file we send a System.Net.HttpWebRequest with our access token that we deserialize with “JsonConvert”.

That returns report id, report name, report webUrl and report embedUrl. We store the access token, the report id and the embedUrl in aspx hidden fields.

 

Our report displays fine on the aspx page but the filters aren’t applied.

We have tried with reports where there are defined "Report Filters" in the report thata re either populated or set to "All".

 

We have tried basic and advanced filters with no joy based on https://community.powerbi.com/t5/Developer/Addling-filter-using-javascript-API-Power-BI-Service/td-p... and https://microsoft.github.io/PowerBI-JavaScript/demo/defaults.html

 

<script src="scripts/powerbi.js"></script>
<script src="scripts/jquery-1.12.4.js"></script>
<script type="text/javascript">
var report = null;

window.onload = function () { 
                var accessToken = document.getElementById('hfAccessToken').value;

                if (!accessToken || accessToken == "") {
                                return;
                }
                
                var metricFilter = {
                                $schema: "http://powerbi.com/product/schema#basic",
                                target: {
                                                table: "Cats",
                                                column: "CatName"
                                },
                                operator: "In",
                                values: ["Mr Furball"]
                }
                var embedUrl = document.getElementById('hfEmbedUrl').value;
                var reportId = document.getElementById('hfReportId').value;

                var config = {
                                type: 'report', 
                                accessToken: accessToken,
                                embedUrl: embedUrl,
                                filters: [metricFilter],
                                id: reportId,
                                settings: {
                                                filterPaneEnabled: false,
                                                navContentPaneEnabled: false
                                }
                };
                var reportContainer = document.getElementById('reportContainer');
                report = powerbi.embed(reportContainer, config); 
};
</script>

<asp:HiddenField ID="hfEmbedUrl" runat="server" />    
<asp:HiddenField ID="hfReportId" runat="server" />
<asp:HiddenField ID="hfAccessToken" runat="server" /> 

<div class="divDashboardContainer" id="reportContainer"></div>
</div>

Can anyone shed any light on why the javascript may not applying the filters ?

 

2 REPLIES 2
shaunwilks Member
Member

Re: API and Javascript filtering

Anyone with some thoughts ?

casaredo Frequent Visitor
Frequent Visitor

Re: API and Javascript filtering

Hello,

Sorry, Can you teach me how do you generate the Access Token and Refresh Token? i have many problems with this. Smiley Mad

 

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 143 members 1,641 guests
Please welcome our newest community members: