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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors