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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
pratikthakor
Regular Visitor

change data set sql statement via api

Is it possible to change SQL statement of the dataset via API call? 

 

My Scenario: I have data in multiple tables in SQL Server. I have created a SQL query with joins to fetch the required data. I created a SQL server dataset by providing that query in the SQL Statement section and published it on the Power BI workspace. Now, I want to modify that SQL Statment programmatically.

 

Any pointer or help is much appreciated. 

 

 SQL Statment Power BI.PNG

1 ACCEPTED SOLUTION

Hi @pratikthakor,

 

>>"use query parameter with t-sql query as optional parameter in sql connector", is there any tutorial or document there to show steps on how to achieve it?

Sure, below is a simple sample, you can test on it.

 

let
	tsql=queryparameter,//query parameter is your t-sql string parameter
	Source= Sql.Database("ServerName", "databaseName", [Query=tsql])
in
    Source

 

 

Reference link:

Sql.Database

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @pratikthakor,

 

Yes, it is possible to use query parameter with t-sql query as optional parameter in sql connector.

 

AFAIK, current power bi not support dynamic table structure.(column amount, column name)

 

So if you change sql query on service side, you need to confirm result table has same structure, otherwise it will return error when refresh data.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

How can I, "use query parameter with t-sql query as optional parameter in sql connector", is there any tutorial or document there to show steps on how to achieve it?

Hi @pratikthakor,

 

>>"use query parameter with t-sql query as optional parameter in sql connector", is there any tutorial or document there to show steps on how to achieve it?

Sure, below is a simple sample, you can test on it.

 

let
	tsql=queryparameter,//query parameter is your t-sql string parameter
	Source= Sql.Database("ServerName", "databaseName", [Query=tsql])
in
    Source

 

 

Reference link:

Sql.Database

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.