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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Direct query syntax returns data in PowerQuery perfectly but shows error when update PowerBI project

When I run this Direct query syntax (calling a stored procedure in SQL Server) it returns data in PowerQuery perfectly without error and displays the returned data in the table.

FrankKrogh_0-1693319134167.png

However when I when try to save my PowerBI Desktop project I receive an error message that does not make much sence to me:

Microsoft SQL: Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near ')'.

 

So how can there be an error when the data from the query already are returned and displayed in PowerQuery? 🤔

1 ACCEPTED SOLUTION
cpwebb
Microsoft Employee
Microsoft Employee

I wrote a blog post about this:

https://blog.crossjoin.co.uk/2022/03/06/why-not-all-sql-queries-can-be-used-as-a-source-in-power-bi-...

Basically, if you can't use your SQL query as a subquery then you can't use it as a source in DirectQuery mode. The only workaround I'm aware of is this: https://prologika.com/power-bi-directquery-with-parameterized-stored-procedure/

 

You can use a table valued function as a source in DirectQuery mode though: https://blog.crossjoin.co.uk/2022/02/20/tsql-table-valued-functions-and-dynamic-m-parameters-in-powe...

 

View solution in original post

7 REPLIES 7
cpwebb
Microsoft Employee
Microsoft Employee

I wrote a blog post about this:

https://blog.crossjoin.co.uk/2022/03/06/why-not-all-sql-queries-can-be-used-as-a-source-in-power-bi-...

Basically, if you can't use your SQL query as a subquery then you can't use it as a source in DirectQuery mode. The only workaround I'm aware of is this: https://prologika.com/power-bi-directquery-with-parameterized-stored-procedure/

 

You can use a table valued function as a source in DirectQuery mode though: https://blog.crossjoin.co.uk/2022/02/20/tsql-table-valued-functions-and-dynamic-m-parameters-in-powe...

 

Anonymous
Not applicable

Excellent solution! I have tried many approaches and almost given up. Today I finally managed to finish my PowerBI views. It really made my day! 🙂

foodd
Community Champion
Community Champion

Nothing like getting the solution from the one and only source  🙂  Sign up for his Blog update if you have not already.

Confirmed. The workaround works.

foodd
Community Champion
Community Champion

Thank you Chris for taking the time to help with this.

foodd
Community Champion
Community Champion

When you save "save project", are you meaning 'publish to Service'? Is this SQL Server on-prem?   Is there a Gateway between upstream and downstream?

Anonymous
Not applicable

I am sorry that I forgot to mention that I am saving the project in PowerBI Desktop.

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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