Forum Discussion

bharukc's avatar
bharukc
Helper I
4 years ago
Solved

Change data source from odbc to post gres

I have multiple reports built using odbc connection. Now I am able to use direct postgres to make those reports.

is there a way to swap data sources? 

  • bharukc it is pretty straightforward, connects to a table using your new PostgreSQL connector, and once it is done, click advanced editor and get the following information from postgres SQL  table you just added

     

    let
        Source = PostgreSQL.Database("servername","database"),
        postgrestable = Source{[Schema="schemaname",Item="table"]}[Data]
    in
       postgrestable

     

    in the above example, I will copy the source and postgrestable lines (2 lines) 

     

    and in my excel table, click advanced editor and will replace the excel connection with PostgreSQL lines

     

    let
        Source = Excel.Workbook(File.Contents("myexcelfile.xlsx"), null, true),
        Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date of Service", type date}, {"Column2", type text}, {"Column3", type text}, {"Daily", type text}, {"Weekly", type text}, {"Monthly", type text}, {"Quarterly", type text}, {"Column8", type any}, {"Column9", type any}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Date of Service", "Column2", "Column3"})
    in
        #"Removed Other Columns"

     

    I will remove the lines from "Source" to "Promoted Header" (3 lines) and replace these with two lines from PostgreSQL table and in the "change type" step I will replace "Promoted Header" with the previous step which will be "postgrestable".

     

    I hope this will get you started if you run into any issues, let me know.

     

     

2 Replies

  • bharukc it is pretty straightforward, connects to a table using your new PostgreSQL connector, and once it is done, click advanced editor and get the following information from postgres SQL  table you just added

     

    let
        Source = PostgreSQL.Database("servername","database"),
        postgrestable = Source{[Schema="schemaname",Item="table"]}[Data]
    in
       postgrestable

     

    in the above example, I will copy the source and postgrestable lines (2 lines) 

     

    and in my excel table, click advanced editor and will replace the excel connection with PostgreSQL lines

     

    let
        Source = Excel.Workbook(File.Contents("myexcelfile.xlsx"), null, true),
        Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date of Service", type date}, {"Column2", type text}, {"Column3", type text}, {"Daily", type text}, {"Weekly", type text}, {"Monthly", type text}, {"Quarterly", type text}, {"Column8", type any}, {"Column9", type any}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Date of Service", "Column2", "Column3"})
    in
        #"Removed Other Columns"

     

    I will remove the lines from "Source" to "Promoted Header" (3 lines) and replace these with two lines from PostgreSQL table and in the "change type" step I will replace "Promoted Header" with the previous step which will be "postgrestable".

     

    I hope this will get you started if you run into any issues, let me know.