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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register 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
Community Champion
Community Champion

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.

Anonymous
Not applicable

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

edhans
Community Champion
Community Champion

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.