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

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

Reply
Anonymous
Not applicable

make a function to getdata from different databases

Hi,

 

i have an SQL database with several "customer" tables over different databases. Of course i can load them seperately and with append-queryies merge them in a new table.

 

Now i want to be more flexible because i have over the 15 databases.

 

The different names of the databases can i save in new table (in my example 001, 002, 003 etc) . After that i want to invoke a funtion that for each database load the "customer" table and merge it in a new table.

let
    Source = Sql.Databases("Server"),
    #"001" = Source{[Name="001"]}[Data],
    customer1 = #"001"{[Schema="dbo",Item="customer"]}[Data],
in
    customer1
- - - - - - - - - - - - -
let
    Source = Sql.Databases("Server"),
    #"002" = Source{[Name="002"]}[Data],
    customer2 = #"002"{[Schema="dbo",Item="customer"]}[Data],
in
    customer2

 

Can someone help me make this function and how to implementate this?

With kind regards

 

2 ACCEPTED SOLUTIONS
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

Create your own function that uses the table as parameter.

I will not be able to post here the complete function, but I will put down an example how to achieve this

function could look like:

(customertable) =>
let
    Source = Sql.Databases("Server"),
    #"001" = Source{[Name=customertable]}[Data],
    customer = #"001"{[Schema="dbo",Item="customer"]}[Data],
in
    customer

 

then create a table and add new column to invoke the function (code is not tested)

let
    Table = #table({"Customer""}, {{"001"},{"002"},{"003"}},
    AddColumn = Table.AddColumn(Table,"SQL",each YourFunctionName([Customer]))
in
    AddColumn

 

If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun

Jimmy

 

View solution in original post

Anonymous
Not applicable

this was the solution:

 

(Databasenaam, Tabelnaam) =>
let
    Bron = Sql.Databases(Server),
    Database = Bron{[Name=Databasenaam]}[Data],
    Tabel = Database{[Schema="dbo", Item=Tabelnaam]}[Data]
in
    Tabel

 

let
    Table = Databases,
    Records = Table.AddColumn(Table, "Records", each HaalTabelOpUitDB([Databasenaam], "bedryf"))
in
    Records

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

this was the solution:

 

(Databasenaam, Tabelnaam) =>
let
    Bron = Sql.Databases(Server),
    Database = Bron{[Name=Databasenaam]}[Data],
    Tabel = Database{[Schema="dbo", Item=Tabelnaam]}[Data]
in
    Tabel

 

let
    Table = Databases,
    Records = Table.AddColumn(Table, "Records", each HaalTabelOpUitDB([Databasenaam], "bedryf"))
in
    Records

 

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

were you able to solve the problem with any reply given?

If so, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

All the best

Jimmy

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

Create your own function that uses the table as parameter.

I will not be able to post here the complete function, but I will put down an example how to achieve this

function could look like:

(customertable) =>
let
    Source = Sql.Databases("Server"),
    #"001" = Source{[Name=customertable]}[Data],
    customer = #"001"{[Schema="dbo",Item="customer"]}[Data],
in
    customer

 

then create a table and add new column to invoke the function (code is not tested)

let
    Table = #table({"Customer""}, {{"001"},{"002"},{"003"}},
    AddColumn = Table.AddColumn(Table,"SQL",each YourFunctionName([Customer]))
in
    AddColumn

 

If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun

Jimmy

 

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

The below syntax will list all the database, then you will be able to reference this as a connection and expand all the tables you need and append together.

let
    Source = Sql.Databases("Server") 
in
    Source

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors