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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
powerbidev123
Responsive Resident
Responsive Resident

Issue while using stored procedure in SQL server database

image (2).png

 

Hi community,

 

Is there a way to fix this because manually inserting the customerid works but when I try to make it parameterized then it gives the above error

 

Any kind of suggestion would be helpful

 

Thanks

1 ACCEPTED SOLUTION
v-huijiey-msft
Community Support
Community Support

Hi @powerbidev123 ,

 

Thanks for the reply from girishthimmaiah .

 

Assuming that your

Server = X

Database = Y

Table name = Z

 

The sample SQL query is (as if you put it on SSMS)

select *
from z
WHERE [customerid]=2

vhuijieymsft_0-1739517496647.png

 

The conversion to M-code is:

let
    Source = Sql.Database("vm1", "TutorialDB", [Query="select *#(lf)from Customers#(lf)WHERE [customerid]=2#(lf)"])
in
    Source

vhuijieymsft_1-1739517496648.png

 

Now, if you want to pass parameters to the where clause as Parameter1, (e.g. Parameter1 =2) make sure they are text first.

vhuijieymsft_2-1739517513849.png

 

You can create a custom query as follows:

let
    Source = Sql.Database("x", "y", [Query="select *#(lf)from z#(lf)WHERE [customerid]="&Parameter1&"#(lf)"])
in
    Source

vhuijieymsft_3-1739517513850.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

4 REPLIES 4
v-huijiey-msft
Community Support
Community Support

Hi @powerbidev123 ,

 

My following up is just to ask if the problem has been solved?

 

If so, can you accept the correct answer as a solution or share your solution to help other members find it faster?

 

Thank you very much for your cooperation!

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

v-huijiey-msft
Community Support
Community Support

Hi @powerbidev123 ,

 

My following up is just to ask if the problem has been solved?

 

If so, can you accept the correct answer as a solution or share your solution to help other members find it faster?

 

Thank you very much for your cooperation!

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

v-huijiey-msft
Community Support
Community Support

Hi @powerbidev123 ,

 

Thanks for the reply from girishthimmaiah .

 

Assuming that your

Server = X

Database = Y

Table name = Z

 

The sample SQL query is (as if you put it on SSMS)

select *
from z
WHERE [customerid]=2

vhuijieymsft_0-1739517496647.png

 

The conversion to M-code is:

let
    Source = Sql.Database("vm1", "TutorialDB", [Query="select *#(lf)from Customers#(lf)WHERE [customerid]=2#(lf)"])
in
    Source

vhuijieymsft_1-1739517496648.png

 

Now, if you want to pass parameters to the where clause as Parameter1, (e.g. Parameter1 =2) make sure they are text first.

vhuijieymsft_2-1739517513849.png

 

You can create a custom query as follows:

let
    Source = Sql.Database("x", "y", [Query="select *#(lf)from z#(lf)WHERE [customerid]="&Parameter1&"#(lf)"])
in
    Source

vhuijieymsft_3-1739517513850.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

girishthimmaiah
Resolver I
Resolver I

80% of your text is likely AI-generated

New version:
It seems that Power BI is attempting to execute a stored procedure (SI_PowerBI_TalentPool), but it requires a @customerid parameter that isn't being passed correctly. When you input the customer ID manually, it works fine, but when you try to make it dynamic (likely using a parameter or slicer), it doesn't function as expected.

How to Fix It
Here are a few suggestions you can try:

1. Properly Define the Parameter in Power Query
Open the Power Query Editor in Power BI.
Navigate to Manage Parameters → New Parameter.
Name it customerid, and set its type to Text or Number (depending on what your SQL procedure requires).
Assign a default value (just for testing purposes).
2. Adjust the SQL Query to Incorporate the Parameter
If you're writing the query directly in Power BI, you might have something like:

sql

EXEC SI_PowerBI_TalentPool @customerid = '12345'
Instead, modify it to:

sql

EXEC SI_PowerBI_TalentPool @customerid = @customerid.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors