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

Dynamic SQL data import and directquery

Hi,

 

I would like to build reports based on information contained in tables on a sql server. The sql server contains multiple tables (one for each datatype).

 

I have written this function in power query : 

 

 

 

let
    GetTableFromDataBase = (schema as text, id_file as text, tablename as text) => let
    Source = Sql.Database("xxx.database.windows.net", "xxx", [Query="SELECT * FROM "&schema&"."&tablename&" WHERE [id_file]="&id_file])
in
    Source
in
    GetTableFromDataBase

 

 

 

Then i invoked the function on a query containing 3 collumns (schema,id_file,tablename) to get each table that i need but this steps gives me this warning message:

 

"Step results in a query not supported in DirectQuery Mode"

 

Is there any way to do this without losing the DirectQuery Mode?

 

EDIT: 

 

EDIT:
I tried some other ways to make dynamic import using directquery, this query (using parameters) is supported in DirectQuery:

 

let
Source = Sql.Database(ServerAdress, DbName),
GoTable = Table.SelectRows(Source{[Schema=schema,Item=tablename]}[Data],each [id_file]=id_file)
in
GoTable


But if i take the same query and convert it to a function then call it using the same parameters PowerBi switches to import mode, this is a simple query why wouldn't it be DirectQuery compatible?

 

Thanks.

 

Thanks.

 

2 REPLIES 2
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please refer to this post to ensure that your tables remained in DirectQuery mode.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

I edited the issue, the solution might be not calling custom functions?

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.