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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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

3 REPLIES 3
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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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