Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Juramirez
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
v-ljerr-msft
Employee
Employee

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

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 ! 😄

@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

Thanks @gilbertocrespo

 

Let me check if it works for me! 

 

Regards

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

Hi @Juramirez

 

I want the Same in C# Code but with different parameters 'Start Date' and 'End Date'. I have done this on power bi desktop with Manage parameter functionality and it works fine but Now I Want to pass these parameters dynamicaly from C# Code. Can you please update me for the same if you have any idea.

 

Thanks in Advance.

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.

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

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?

Hi @gilbertocrespo

 

Ok, thanks for your explain. The question that you're doing to @v-ljerr-msft is the one that i need to solve. Any answer for this one?


Thanks in advance.

I'm waiting for something new here 🙂

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.