Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

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 the souce step (in the editor) and change the DB name. In this way I get identical data for the new DB, and I need to repeat this operation many times

What I'd like to have is a dynamic way to retrieve the DB name in a column of my query. So what I'd like to do is add a column which retrieves the DB name from the source, but it has to be dynamic and not hardcoded. In this way each time I copy a query and change the DB name I will retrieve the correct DB name in the column without having to change an hardcoded value

Is it possible? Maybe with parameters or something? 
Thanks for any help 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

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

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

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

I don't have this table in my database.

Anonymous
Not applicable

Perfect!

I have combined this with a parameter and made it even easier to pick my DB (now it's just one click in the parameter list and I have both the correct databse and column populated!)

Thanks a lot

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors