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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
SagarB
Frequent Visitor

Stored procedures with parameters in a Direct Query connection

How to get data from a SQL-server by using stored procedures with parameters in a Direct Query connection?

Facing Error (Microsoft SQL: Incorrect syntax near the keyword 'EXEC') 
I've tried using Power Query's advanced editor and creating new parameters still facing the same error, but I'm wondering if there are any other methods I could try.

1 ACCEPTED SOLUTION
VijayP
Super User
Super User

@SagarB 

CREATE VIEW MyView AS
SELECT * FROM MyTable WHERE Column1 = 'Value1';

or use Query Folding by adding extra steps in using M Language

#"Filtered Rows" = Table.SelectRows(Sales, each [SaleDate] >= #date(2023, 1, 1) and [SaleDate] <= #date(2023, 12, 31))




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


View solution in original post

5 REPLIES 5
VijayP
Super User
Super User

@SagarB 

CREATE VIEW MyView AS
SELECT * FROM MyTable WHERE Column1 = 'Value1';

or use Query Folding by adding extra steps in using M Language

#"Filtered Rows" = Table.SelectRows(Sales, each [SaleDate] >= #date(2023, 1, 1) and [SaleDate] <= #date(2023, 12, 31))




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


VijayP
Super User
Super User

@SagarB  Oh! I missed that , DirectQuery mode in Power BI does not support the execution of stored procedures directly. Instead, create a view or a table-valued function in the database and query this object in Power BI




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


SagarB
Frequent Visitor

@VijayP  Thank you. I have one question: for view can we pass parameters?

SagarB
Frequent Visitor

@VijayP  "I reviewed the thread you mentioned, and it clearly states that this solution will only work for Import Mode. However, I am using Direct Query mode."

VijayP
Super User
Super User

@SagarB 

Please use this thread - https://community.fabric.microsoft.com/t5/Power-Query/Microsoft-SQL-Incorrect-syntax-near-the-keywor...




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors