Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi,
I would like to inquire about a method for dynamically entering database credentials (SQL Server name, username, password, and port) in Power BI. Specifically, I want these credentials to be stored in an Excel file, and for Power BI to fetch them dynamically during each data refresh.
Please advise on how this can be accomplished?
Solved! Go to Solution.
Hi All,
Firstly @lbendlin thank you for your solution!
And @mujibjee , You are trying to implement a query for dynamic input of data credentials, right?
Here's a solution we've found for you, and we hope you find it helpful:
1.Store Credentials in an External File (Excel or Config File):
Create an Excel file or any external configuration file to store the database credentials (e.g., server name, username, password, port).
Format the file as a table with appropriate headers, such as Server, Username, Password, and Port.
2.Use M Code (Power Query) to Fetch and Apply Credentials:
Open the Advanced Editor in Power Query and reference the imported credentials dynamically.
Example:
let
Source = Excel.Workbook(File.Contents("PathToYourExcelFile.xlsx"), null, true),
ConfigTable = Source{[Name="YourTableName"]}[Content],
Credentials = Table.ToRecords(ConfigTable),
ServerName = Credentials{0}[Server],
Username = Credentials{0}[Username],
Password = Credentials{0}[Password],
Port = Credentials{0}[Port],
ConnectionString = "Server=" & ServerName & ";Port=" & Port
in
ConnectionString
3.Dynamic Connection Setup:
Replace hardcoded database connection details with the variables (ServerName, Username, Password, Port) in the connection settings for your data source.
4.Refresh Configuration during Updates:
Power BI will fetch the updated credentials from the external file during every data refresh.
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi All,
Firstly @lbendlin thank you for your solution!
And @mujibjee , You are trying to implement a query for dynamic input of data credentials, right?
Here's a solution we've found for you, and we hope you find it helpful:
1.Store Credentials in an External File (Excel or Config File):
Create an Excel file or any external configuration file to store the database credentials (e.g., server name, username, password, port).
Format the file as a table with appropriate headers, such as Server, Username, Password, and Port.
2.Use M Code (Power Query) to Fetch and Apply Credentials:
Open the Advanced Editor in Power Query and reference the imported credentials dynamically.
Example:
let
Source = Excel.Workbook(File.Contents("PathToYourExcelFile.xlsx"), null, true),
ConfigTable = Source{[Name="YourTableName"]}[Content],
Credentials = Table.ToRecords(ConfigTable),
ServerName = Credentials{0}[Server],
Username = Credentials{0}[Username],
Password = Credentials{0}[Password],
Port = Credentials{0}[Port],
ConnectionString = "Server=" & ServerName & ";Port=" & Port
in
ConnectionString
3.Dynamic Connection Setup:
Replace hardcoded database connection details with the variables (ServerName, Username, Password, Port) in the connection settings for your data source.
4.Refresh Configuration during Updates:
Power BI will fetch the updated credentials from the external file during every data refresh.
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.