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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Nicki
Helper III
Helper III

Updated Server and database Name dynamically

Hello,

Is there any way to update server name and database name in power BI desktop by reading from a file, query or API?

After that data will  be updated in Power BI desktop automatically.

 

Thanks

Nicki

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

You can use a query to pull that name in. Make it a scalar value - just right-click on the final result and Drill Down. That will show something as a text value. Rename the query to something like varServerName, and be sure to right-click on that and uncheck "Enable Load"

 

Then, in the actual query where you need this replace the server name with varServerName.

So:
= Sql.Database("Some_Server_Name", "DATA")

becomes
= Sql.Database(varServerName, "DATA")

 

Do the same with the database name.

You can see a bit more about this in my Dynamic Date Table post. I use the same logic to get a start and end date for a date table. Same concept, except you'll be getting a text value for a server name instead of a date value.

Creating a Dynamic Date Table in Power Query



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
cnschulz
Helper IV
Helper IV

This does NOT work on Power BI Report Server. This is amazingly frustrating.

watkinnc
Super User
Super User

You can reference an external Excel file for that.  Let's say you have a SQL server and database source like:

Sql.Databases("DESKTOP-738NO1A\SQLEXPRESS")

 

If you have an excel file with a table with two columns: DataSource, Value

DataSource can be AdventureWorks, Value can be "DESKTOP-738NO1A\SQLEXPRESS".

 

Use Excel.Workbook to query the excel file, choose that table, right click the "cell' in which your "DESKTOP-738NO1A\SQLEXPRESS" resides. Nae that query something, like SQLSource.

Now, you can go back and change the source in  AdventureWorks to SQL.Databases(SQLSource)

 

So now whenever you update that excel sheet, you are hanging the source as well--once you refresh they query.

 

---Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
edhans
Super User
Super User

You can use a query to pull that name in. Make it a scalar value - just right-click on the final result and Drill Down. That will show something as a text value. Rename the query to something like varServerName, and be sure to right-click on that and uncheck "Enable Load"

 

Then, in the actual query where you need this replace the server name with varServerName.

So:
= Sql.Database("Some_Server_Name", "DATA")

becomes
= Sql.Database(varServerName, "DATA")

 

Do the same with the database name.

You can see a bit more about this in my Dynamic Date Table post. I use the same logic to get a start and end date for a date table. Same concept, except you'll be getting a text value for a server name instead of a date value.

Creating a Dynamic Date Table in Power Query



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors