Forum Discussion
Help needed to pass a dynamic parameter value to a dataset when embedding a report
- Anonymous3 years ago
Hi StephenL_CA,
The error message seems related to the data source credentials, I think you may need to re-verify them before invoke the API to refresh.
Regards,
Xiaoxin Sheng
HI StephenL_CA,
How did you design the report? have you parameterized your stored procedure with query parameters?
You should parameterize the query parameters with your stored procedure at the first.
After you publish and embeded this report, you can use updateParameters and setFilters methods to update and interact with backend query parameters.
Sample code:
// Get a reference to the embedded report
var report = powerbi.embed(reportContainer, config);
// Define the list of parameter values
var parameterValues = [
{
name: "Parameter1",
value: "Value1"
},
{
name: "Parameter2",
value: "Value2"
}
];
// Update the parameter values
report.updateParameters(parameterValues)
.then(function () {
// Set the filters based on the updated parameter values
var filters = [
{
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table1",
column: "Column1"
},
filterType: 1,
operator: "In",
values: [parameterValues[0].value]
},
{
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table2",
column: "Column2"
},
filterType: 1,
operator: "In",
values: [parameterValues[1].value]
}
];
// Set the filters on the report
report.setFilters(filters);
});
Power BI embedded analytics Client APIs | Microsoft Learn
Regards,
Xiaoxin Sheng
Thank you for the reply.
Now I have change mind. I use .Net SDK to do what I am trying to accomplish: update the parameter value then get the embedded report. But then I get "This operation is only supported for the dataset owner".
Some background info: my web app is written in C# MVC. The app is registered through Azure AD. It is a service principal , App Owns Data approach. I have the tenant id, appId, App secret. In the C# code I have the pbiClient instantiated with the proper credentials, proof is that I have no issue embedding the report to my web app. The dataset that I am trying to update the parameter, the service principal has all permissions in Power BI service on it though someone else designed the report on Power BI Desktop, thus the dataset creator or owner is that person, I am not sure if this is relevant. Here is the code snippet.
facilityId = Text.From(PortalFacilityID),
Source = Sql.Database("sac1v-sqlent-1", "DivrProd",
[
Query="exec dbo.SelectRecoveryTrendDataParameter @PortalFacilityID = ' " & facilityId & " ' "
]
)
in
Source
- StephenL_CA3 years agoFrequent Visitor
Ok, continue on the previous reply from myself. I overcome the error by adding TakeOver()
Also, I added RefreshDatasetsInGroup(), thinking that would refresh the report with new data loaded with the new parameter value. But no, the embedded report still has the old data. And when I go to Power Bi service the dataset I see:
Please, could you tell me what else is missing in my steps?
- Anonymous3 years agoNot applicable
Hi StephenL_CA,
The error message seems related to the data source credentials, I think you may need to re-verify them before invoke the API to refresh.
Regards,
Xiaoxin Sheng
- pcho2 years agoFrequent Visitor
Hi StephenL_CA, I know this is an old post, did you get a final solution? thank you for the post.
-Peter
- StephenL_CA2 years agoFrequent Visitor
Not really finding a solution, I gave up going down this path.