Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Dynamically retrieving the DB name from the source in a column

Hi Everyone I need to copy multiple queries which are absolutely identical. The only change I make to these queries is the data source. Basically what I do is a copy of the query and then I go in ...
  • Jimmy801's avatar
    6 years ago

    Hello Anonymous 

     

    what do you think of using a Variable for you DB-name and using this in the datasource as well as for adding a new column?

    Here the code

    let
        VARDB = "YOURDATABSENAME",
        Quelle = Sql.Database(VARDB, "Extension"),
        dbo_V_BSM_SummaryReportLarge = Quelle{[Schema="dbo",Item="V_BSM_SummaryReportLarge"]}[Data],
        Add = Table.AddColumn(dbo_V_BSM_SummaryReportLarge, "DB-Name", each VARDB)
    in
        Add

     

    If this post helps or solves your problem, 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

    Have fun

    Jimmy