cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver I
Resolver I

Get value from C# app to Power BI Embedded

Hi!

 

I have my Power BI Reports embedded in a C# app. This app sends by JS a parameter when you select from the home page certain value. I want to catch this value into power BI report and use it to do dynamic titles, filters, etc... How can I do that?

Thanks!


Julián

11 REPLIES 11
Highlighted
Microsoft
Microsoft

Hi @Juramirez,

 

Following is a good answer from this similar thread(check the bold in the code, you can set the value for the filter there). Smiley Happy

The Power BI Javascript support set filter when embedding. Check this wiki. You can find a more integrated live demo by clicking Custom Filter Pane.

 

A simple demo I use to test for your reference.

 

<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">
var embedConfiguration = {
    type: 'report',
    accessToken: 'token',
    embedUrl: 'embedURL' 
}; 

var report;

window.onload = function () { 

var $reportContainer = $('#reportContainer');
 
 report= powerbi.embed($reportContainer.get(0), embedConfiguration);
 
 
 var Filter1 = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table1",
column: "T1id"
},
logicalOperator: "OR",
conditions: [
{
operator: "Contains",
value: "id1"
} 
]
}
 
report.on('loaded', event => {
  report.getFilters()
    .then(filters => {
	
      filters.push(Filter1); 
return report.setFilters(filters); }); }); } function reloadreport(){ var $reportContainer = $('#reportContainer'); powerbi.embedNew($reportContainer.get(0), embedConfiguration); }; </script> <div id="reportContainer"></div> </html>


 

Regards

Highlighted

Thanks @v-ljerr-msft for your answer but that's what I've just donde and it works perfectly. What I want now is to get the URL value  into power BI and this way that I can execute an Stored Procedure to bring only the data that I want from SQL Server. I mean, for example, in my app I log in with a user that has as idFromURL = "USER1" and this id is right now being passed by url and is filtering all the data of all the users (because the database bring everything) by this id but if I can get this id into the moment that power bi goes to de DB and filter it by an SP (or something that just bring me the data respect that id). I expect something like this: 

Sql.Database("server", "database", [Query="EXEC sp_BringDataByUserID @User = 'idFromURL' "])

 

Hope you can help me ! 😄

Highlighted

I'm waiting for something new here 🙂

Highlighted

@Juramirez  this link really save my life 🙂

https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedded-rls/

ONE line difference. Just a small adjustment on power bi desktop.

 

Also, they updated the sample https://github.com/Microsoft/PowerBI-Developer-Samples/tree/master/App%20Owns%20Data

 

Enjoy

Highlighted

Thanks @gilbertocrespo

 

Let me check if it works for me! 

 

Regards

Highlighted

Hi @gilbertocrespo.

 

How did you get the value from the URL? I mean, i'm passing an ID by URL but i don't know how to get this value in my advanced editor to call an StoredProcedure (SQL Server) with this ID as value for my StoredProcedure. I want something like this: 

Sql.Database("server", "database", [Query="EXEC sp_BringDataByUserID @User = 'idFromURL' "])

 

Regards

Highlighted

I guess you are focusing on Stored Procedure too much. Let the PowerBI does this service to you.

 

 

On controller Home\HomeController.cs,  before to generate token:

 

var generateTokenRequestParameters = new GenerateTokenRequest("View", null, identities: new List<EffectiveIdentity> { new EffectiveIdentity(username: "5", datasets: new List<string> { report.DatasetId }, roles: new List<string> { "clientid" }) });

 

5 is my clientId

clientid is the collumn name I created on each report

 

 

On PowerBI Desktop:

Enter the following DAX expression on your report:

[clientid] = VALUE( USERNAME() )

 note: I'm using value() to converts my string into int

 

This way your data is filtered BEFORE to bring it to PowerBi Service.

Highlighted

Thanks for your reply @gilbertocrespo

 

With the code that you give me is like filtering a dataset that has all the Clients, am I wrong? I mean, you're importing all database and with this you're allowing to see the data refered to the clientid that is getting in.  This way the dataset size is the same for a huge Client than a small client or not? I want a SP because this way (as I thought) I can bring the data directly (not filtering or by permissions) from my DB only for the client that is getting in and this way the size will be different depending the client size.

 

Regards

Highlighted

Hello my friend @Juramirez,

My current database is small and i don't see any difference.

 

Filter does that you talking about, because it works after the report is built.

I'm not 100% sure, but RLS don't does it.

 

@v-ljerr-msft Could you help us solving this question?

Does the dataset size brought by powerBI service is the same if I filter it by using RLS?  I mean, Does the Power BI just hide a content or includes a WHERE clause when building a dataset transported?

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors