Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Append Queries Question

I have to do identical reports from 2 differerent PostgresSQL databases.  Ideally, I would be able to merge the two queries so that I just have to create the report once.  However, I would still like to be able to identify which database the information came from so I can filter.  One database is TEST and one is PRODUCTION.  They both have identical fields and there is nothing in the data that would indicate which database each record comes from.  

Anyone have any ideas on this?  Is there a way to indicate which database each record comes from that would also apply to new records when I refresh?

 

5 Replies

  • PattemManohar's avatar
    PattemManohar
    Community Champion

    Anonymous Try adding an additional field in your SELECT statement (using SQL Statment) option while importing. Something, similar to this...

     

    SELECT c1,c2,'TEST' as DB FROM TEST.Table1
    
    UNION ALL
    
    SELECT c1,c2,'PRODUCTION' as DB FROM PRODUCTION.Table2

     

  • for example, if u get data from odbc

    Try to create table with db_id like

    and add new column with subquery like

    =Table.AddColumn(Source, "Custom", each Odbc.Query([db_name],"select * from table_name"))

    Next step expand data and create new primary key, merge db_name and primary key table. 

    Unfortunately, this model don't support scheduled update in power bi service.