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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Let End-User change parameter Value every Refresh of Power BI Service

I followed this topic to apply filter on data by Stored Procedure using Parameter before data import from database

 

 

https://www.c-sharpcorner.com/article/execute-sql-server-stored-procedure-with-user-parameter-in-pow...

 

Param_in_DataSource.JPG

 

My procedure  doing filter data on temp table , then showing temp table to end-user.

 

CREATE PROCEDURE GET_MO @P_CIC nvarchar(30) = NULL, @AddressLine1 nvarchar(60) = NULL

AS

Truncate table Pol

insert into pol

SELECT *

FROM Policies

WHERE Policies.PolicyFlag = @P_CIC

 

Param_in_DataSource1.JPG

 

Param_in_DataSource2.JPG

and user can check data Report successfully from Power BI Service 

But Parameter value are fixed !!  😞 

  • How can I let end-user change Parameter value !?

 

4 REPLIES 4
Kaszm
New Member

If you are using parameter in powerBi and wnt to change parameter value through backend of your code then you can use this script of powershell

Script:

param(
[string] $parameter="Any_Value-you-want-to-pass-in-store-procedure",
[string] $datasetId= "DatasetId-Of-report-for-which-you-want-to-update-parameter-value"

)
$password = ConvertTo-SecureString "your-powerBi-EmailId-password" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("your-login-EmailId-of-PowerBi", $password)


Connect-PowerBIServiceAccount -Credential $Cred

 

$urlUpdateParams = "https://api.powerbi.com/v1.0/myorg/datasets/$($datasetId)/Default.UpdateParameters"


$newBody= @{
updateDetails=@(
@{
name="Name-Parameter-You-Have-Given-In-Report(Not talking about parameter value)"
newValue="$($parameter)"
}

)

}

$jsonBody= $newBody |ConvertTo-Json

$content = 'application/json'

write-host $urlUpdateParams

Invoke-PowerBIRestMethod -Url $urlUpdateParams -Method POST -Body $jsonBody -ContentType $content

 

 

 

you just have to run this script in ur backend, if somehow you are using .net core than this code will just just fine for you

Backend Code:

 

var file = @"[Enter full path in which you have saved your powershell script file in your PC]";

InitialSessionState initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;


using Runspace runspace = RunspaceFactory.CreateRunspace(initialSessionState);
runspace.Open();
PowerShell ps = PowerShell.Create(runspace);

ps.AddScript(System.IO.File.ReadAllText(file)).AddParameter("parameter",paramValue).AddParameter("datasetId",datasetId).Invoke();

runspace.Close();

 

 

v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please vote the idea up to improve Power BI and make this feature coming sooner.

 

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

anybody have any workaround !!

@v-frfei-msft 

Do we have any workaround for this?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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