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
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
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
Top Kudoed Authors