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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
ChandanGauns
New Member

Running SQL Stored Procedure from Power BI Query

Hi,

I am using DirectQuery Data Mode to fetch data from SQL Server for my Power BI Report. I followed the below steps:

Power BI SQL Server Connection.png

Above configuration generated the following query:

Power BI SQL Server Query.png

 

When I open the Query, I can see the preview of that SP's output.

Power BI SQL Server Preview.png
But when I click on Close and Apply, its giving me the following error:

ChandanGauns_0-1704369442551.png

How do I fix this?

1 ACCEPTED SOLUTION
ChandanGauns
New Member

4 REPLIES 4
ChandanGauns
New Member

Below solution worked for me.

Calling SQL Stored Procedure using OPENROWSET 

ChandanGauns
New Member

hi @amustafa 

 

Below is my query:

 

let
    Source = Sql.Database("1.2.3.4,1234", "MyDB", [Query="EXEC [dbo].[MyStoredProc] '2023'"])
in
    Source

 

I tried using your solution but its not working as expected.

ChandanGauns_1-1704428302115.png

 

I was able to run the following query in Direct Query mode instead of Import Query and load the data form Power Query just fine. I have also made it a paramaterized query. 

 

let
CustomerID = customeridparam,
Source = Sql.Database("localhost", "AdventureWorks",
[Query="EXEC GetCustomerOrderSummary @customer_id = " & Text.From(CustomerID)])
in
Source

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amustafa
Solution Sage
Solution Sage

Can you please paste your full M Code from Power Query? Here's a general code with correct syntax.

 

let
Source = Sql.Database(ServerName, DatabaseName),
Query = "EXEC YourStoredProcedure @Parameter1 = Value1, @Parameter2 = Value2",
Result = Source{[Schema="dbo",Item="YourStoredProcedure"]}[Data]
in
Result





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.