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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors