cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MRZ Frequent Visitor
Frequent Visitor

parameters to SP or Sql query

There is probably a simple answer but after looking all over for an answer and trying various methods, the right code still escapes me.  The scenario is I have a stored procedure that uses two input parameters, a start and end date. If I hard code the date in the call, getting the data works fine. I defined two parameters in Power BI and have been trying to figure out how to call the SP with these 2 paramters. My paramters are named Sdatex and Edatex. Both are defined as date type variables.

here is my call that works:

DECLARE @return_value int

EXEC @return_value = [dbo].[Capacity_SP]

@SDate = '8/11/2016',

@EDate = '8/12/2016'

SELECT 'Return Value' = @return_value

 

I also tried to execute the SP code (a CTE) insted of the SP and I have the same issue. Hard coded dates work but I do not know how to tell Power BI that I want the paramters (Sdatex and Edarex) used instead of the date.

Any help would be appreciated.

2 ACCEPTED SOLUTIONS

Accepted Solutions
MRZ Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

Thank you so much. Will give this a go as soon as possible.

MRZ Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

By the way, this work fine. Thanks so much. Now I need to find out how to update the parameters in PowerBI.com so that i can refresh the data as needed. Thanks again.

25 REPLIES 25
Highlighted
Moderator v-yuezhe-msft
Moderator

Re: parameters to SP or Sql query

Hi @MRZ,

I made a test to call stored procedure with parameters in Power BI Desktop. You can review the following example to apply it to your scenario.

In SQL Server, I create a procedure named p4test in test database of v-kaxion2015tes\sql2016tabular server.

Create PROC p4test @sdate date,@edate date
AS
BEGIN
SELECT @sdate StartDate, @edate Enddate
END


1. In Query Editor of Power BI Desktop, click "New source"> "SQL Server", enter server name, database name and statement "exec p4test '8/11/2016', '8/12/2016'", click ok.

2. Right click on that query on the left panel and select Advanced Editor, and paste the below code.

let
    SQLSource = (param1 as date, param2 as date) =>
let  
    Source = Sql.Database("v-kaxion2015tes\sql2016tabular", "test", [Query="exec p4test '"& Date.ToText(param1) & "','" & Date.ToText(param2)&"' #(lf)#(lf)#(lf) #(lf)"])
in
    Source
in
    SQLSource

3.Click “Invoke” button and enter parameter values as shown in the following screenshot.
1.PNG


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MRZ Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

Thank you so much. Will give this a go as soon as possible.

MRZ Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

By the way, this work fine. Thanks so much. Now I need to find out how to update the parameters in PowerBI.com so that i can refresh the data as needed. Thanks again.

Sunkari Member
Member

Re: parameters to SP or Sql query

@v-yuezhe-msft: May i know how this works in Power BI Service. If it is not going to work in Power BI Service, then is there any alternative to achieve the same kind of functionality in Power BI Service

Fugi Regular Visitor
Regular Visitor

Re: parameters to SP or Sql query

We are also looking for a solution to this from the service... it doesn't appear to exist as far as I can tell...

Raghuvardhan Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

Hi All,

 

Can any one Plz help me out ,

 

Is it possible to get the Invoke function , like as a parameter in desktop to pass i/p value as a parameter to my direct query (SP) .

 

Based on that i/p value my data has to be refreshed or updated . 

 

Is it possible to desible  the "Refresh data" or "Edit Permission" warnings messages always .

 

Thanks 

 

Raghu

SvenTexas Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

Thanks Lydia, this worked perfectly.  Would you have any idea how to just pass a textual value, instead of date.  So Text.ToText or similar? 

 

 

anakoom Regular Visitor
Regular Visitor

Re: parameters to SP or Sql query

I have similar issue let me know if you find any solution

SvenTexas Frequent Visitor
Frequent Visitor

Re: parameters to SP or Sql query

Yeh sorry, no solution found yet on text.totext, ended up coding around it unfortunately.  good luck.

Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Top Kudoed Authors
Users Online
Currently online: 27 members 788 guests
Please welcome our newest community members: