Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Multiple Databases with the same Data Source

Hi Guys,

 

I'm intrested in building a report based on multiple databases using the same data source.

I found some leads in the forums, but with no luck to the below.

 

Data source - SQL Server - single gateway

The DB list is based on a dynamic query, i have a list of them in a table called Companies (Select DBName from MainServer.dbo.Companies)

Query - Select * from [DynamicDB].dbo.Transactions

After that, I need to append them all to each other.

 

Any help will be appreciated!

 

PS, i tried using parameters (Server Name and DB), but I couldn't get more then one DB at a time.

 

Regards,

E.

 

 

 

  • Hi Anonymous ,

     

    I got your point and tried to set the query table dynamically:

    1. In query editor pane, New source>SQL server> "Servername" (Keep database name as empty) > IM mode> select one table > Ok, then delete the Navigation step. you'll get the list of database in the first column. 

    2. Right click the column > Add as new query

    3. Then create the parameter based on the query, everytime you refresh the data source, the list will be updated,  we can fetch the data in different DB by switching parameter value.

    But the problem is One parameter works for One database, and fetch one table under it:(DB is the parameter name)

    let
        
        Source = Sql.Databases("MININT-8GMT4UN\SQLEXPRESS"),
        DB = Source{[Name= DB]}[Data]
    in
        DB

    You can select the specific table under the database, and final one is Table1

     

    Then add another new query to get the table 2 :

    Then we can use the M code to append Table1 with Table2 as new table, (Notes Table1 and Table2 are dynamically changing when we switch the parameter).

    let
        Source = Table.Combine({Table_1, Table})
    in
        Source

    Please let me know if it works for you.

     

     

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the reply v-diye-msft ,

       

      Maybe I'm missing something, but I don't understand how your proposed solution is dynamic.

      In my scenario, I don't want to address each source and manually concatenate it with the other sources.

       

      BR,

      Eliran.

      • v-diye-msft's avatar
        v-diye-msft
        Community Support

        Hi Anonymous 

         

        You can add the databse list in the parameter:

        Then connect the SQL server using the current Databse, after fetching the data, then change the database:

        Then try again: Get data>SQL server, both connection mode are fine. then you'll get the data from different databse.