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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
fsim
Responsive Resident
Responsive Resident

connection function and error in the argument passed

hello HiveMind
In our infrastructure, I have multiple environments. For each one, I have a data server whose name changes, as well as 4 databases (which are Bronze_crm, Bronze_FO, Silver, and Gold)  whose names also change with the env.. In other words, the database Bronze_crm, for example, is named "dataverse_schprd_####" in the "prod" environment but "dataverse_####_orgad0fc35e" in the test environment.
I have compiled all the environments and database names into a table "connectors". Based on the value of the [env] column, I can retrieve the server address ([Server] field) as well as the names of the 4 DBs . The purpose of my function is to be able to use an ENVDYN parameter to choose the target environment, then to pass as an argument of my function, the database to which I want to connect and optionally, a SQL query that I would like to execute.
The code of my function is
    (DB as text, optional qury as text) =>
    let
        ParametreTrouve = Table.SelectRows(connectors, each [env] = ENVDYN),
        P_Server = if Table.RowCount(ParametreTrouve) > 0 then ParametreTrouve{0}[Server] else null,
        P_DB = if Table.RowCount(ParametreTrouve) > 0 then Record.Field(ParametreTrouve{0}, DB) else null,
        options = if Value.Is(qury) then Record.AddField([], "Query", qury) else [],
        connection = Sql.Database(P_Server, P_DB, options)
    in
    connection

Unfortunately, I keep having this error msg:
An error occurred in the ‘’ query. Expression.Error: 1 arguments were passed to a function which expects 2.
Details:
Pattern=
Arguments=[List]

The error comes from the query option part of the SQL.database() function.  but I don't see how to pass this query in the function. Any idea would be helpful.
Thanks in advance
Fred

 

1 ACCEPTED SOLUTION
fsim
Responsive Resident
Responsive Resident

if Value.Is(qury)  is the source of the error. (It took me 2 days to figure it out and, guess what, co-pilot didn't spot it)
I replaced it by qury <>"" and it works. 
enjoy the 
(DB as text, optional qury as text) =>
let
ParametreTrouve = Table.SelectRows(connectors, each [env] = ENVDYN),
P_Server = if Table.RowCount(ParametreTrouve) > 0 then ParametreTrouve{0}[Server] else null,
P_DB = if Table.RowCount(ParametreTrouve) > 0 then Record.Field(ParametreTrouve{0}, DB) else null,
connection =
if qury <>"" then
Sql.Database(P_Server, P_DB ,[Query=qury])
else
Sql.Database(P_Server, P_DB)
in
connection

View solution in original post

3 REPLIES 3
fsim
Responsive Resident
Responsive Resident

if Value.Is(qury)  is the source of the error. (It took me 2 days to figure it out and, guess what, co-pilot didn't spot it)
I replaced it by qury <>"" and it works. 
enjoy the 
(DB as text, optional qury as text) =>
let
ParametreTrouve = Table.SelectRows(connectors, each [env] = ENVDYN),
P_Server = if Table.RowCount(ParametreTrouve) > 0 then ParametreTrouve{0}[Server] else null,
P_DB = if Table.RowCount(ParametreTrouve) > 0 then Record.Field(ParametreTrouve{0}, DB) else null,
connection =
if qury <>"" then
Sql.Database(P_Server, P_DB ,[Query=qury])
else
Sql.Database(P_Server, P_DB)
in
connection

Anonymous
Not applicable

Thank you for sharing this solution, it's very helpful!

fsim
Responsive Resident
Responsive Resident

@Anonymous 
unfortunately the report cannot be refreshed by powerBi service anymore. 
https://aka.ms/dynamic-data-sources
Am I the only one that need to change the sources of the queries  when publishing in different environments ?

 

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.