Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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
Solved! Go to Solution.
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
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
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
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
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
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
100 | |
54 | |
21 | |
12 | |
11 |