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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
techVikas
Regular Visitor

Help Using SQL Stored Procedure Parameteric and not parametric in DirectQuery Mode in Power BI

Hi Community,

I'm building a Power BI report using SQL Server as the data source. I want to use an existing stored procedure that takes parameters (e.g., @SiteCode), and I want to keep the connection in DirectQuery mode so the data reflects real-time changes.

Challenges I'm Facing:

The stored procedure is not visible in the navigator when connecting via DirectQuery.

Even when the stored procedure does not use temp tables, I get syntax errors like:

"Incorrect syntax near 'EXEC'"

Or schema inference errors during loading.

I tried using Value.NativeQuery() like this:
let
Source = Sql.Database("192.168.x.x", "MyDB"),
Result = Value.NativeQuery(Source, "EXEC xspMyProcedure @SiteCode='CWPFAB'")
in
Result
But this throws an error during data load or preview.

My Questions:

Is there a supported or recommended approach to using stored procedures with parameters in DirectQuery mode?

Why does Power BI fail to read schema even when temp tables are not used?

Is converting the logic to a view or table-valued function the only stable option?

Is there a way to dynamically pass parameters to the stored procedure from Power BI?

Any help or suggestions would be greatly appreciated!

Thanks,
Vikas

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

HI @techVikas 

 

Have you tried the method suggested here?
https://community.fabric.microsoft.com/t5/Desktop/Calling-SQL-stored-procedure-with-Direct-Query/td-...

 

A fully explanation here:
https://prologika.com/power-bi-dynamic-m-query-parameters-reloaded/

 

Alternatively Chris Webb did a blog about used a Table Valued Function instead:
https://blog.crossjoin.co.uk/2022/02/20/tsql-table-valued-functions-and-dynamic-m-parameters-in-powe...


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

7 REPLIES 7
v-sdhruv
Community Support
Community Support

Hi @techVikas ,

Good to know that your issue got resolved.
Can you please mark the post as "Accept as solution" so that other users can also benefit from it?

Thank you for using Microsoft Community forum

v-sdhruv
Community Support
Community Support

Hi @techVikas ,

Since we didnt hear back, we would be closing this thread.
If you need any assistance, feel free to reach out by creating a new post.

Thank you

Hi @v-sdhruv
your solution helped

thanks

v-sdhruv
Community Support
Community Support

Hi @techVikas ,

Just wanted to check if you had the opportunity to review the suggestions provided?
If you need any assistance, let us know.

Thank You

v-sdhruv
Community Support
Community Support

Hi @techVikas ,

Just wanted to check if you had the opportunity to review the suggestions provided?
If you need any assistance, let us know.

Thank You

v-sdhruv
Community Support
Community Support

Hi  @techVikas ,

If you dont need live data, I suggest you to use import  mode instead of direct query because it's not possible to use a query with common table expressions, nor one that invokes stored procedures.
Refer- Data Transformation Limitations

The resources suggested by Sam is a helpful workaround for this problem.

Additionally, you might to check out-

Can I execute a SP in DirectQuery Mode with or without parameters?

Hope this helps!

SamWiseOwl
Super User
Super User

HI @techVikas 

 

Have you tried the method suggested here?
https://community.fabric.microsoft.com/t5/Desktop/Calling-SQL-stored-procedure-with-Direct-Query/td-...

 

A fully explanation here:
https://prologika.com/power-bi-dynamic-m-query-parameters-reloaded/

 

Alternatively Chris Webb did a blog about used a Table Valued Function instead:
https://blog.crossjoin.co.uk/2022/02/20/tsql-table-valued-functions-and-dynamic-m-parameters-in-powe...


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.