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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.