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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

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

@v-jingzhan-msft 
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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors