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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mujibjee
New Member

Query on Dynamically Entering Database Credentials in Power BI

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?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.



View solution in original post

2 REPLIES 2
Anonymous
Not applicable

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.



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors