The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi All,
I'm using Power BI desktop and I need to get an excel file from a remote folder using:
Excel.Workbook(File.Contents("\\path_to_remote\excel.xlsx"), null, true)
But I must use a specific username and password to access that file.
How can I pass credentials in the power query statement?
Thank you so much for your attention and participation.
Solved! Go to Solution.
@vetty In Power Query within Power BI Desktop, you can pass credentials to access a remote file using the Web.Contents function to fetch the file. You can include the username and password as part of the request headers. Here's how you can do it:
let
// Define the URL of the remote file
url = "\\path_to_remote\excel.xlsx",
// Define your username and password
username = "YourUsername",
password = "YourPassword",
// Encode the credentials in base64
encodedCredentials = Binary.ToText(Text.ToBinary(username & ":" & password), BinaryEncoding.Base64),
// Create a custom header with the Authorization token
headers = [#"Authorization" = "Basic " & encodedCredentials],
// Fetch the file using Web.Contents with the custom headers
source = Excel.Workbook(
Web.Contents(url, [Headers=headers]),
null,
true
)
in
source
Replace "YourUsername" and "YourPassword" with your actual credentials.
If you find this insightful, please provide a Kudo and accept this as a solution.
@vetty In Power Query within Power BI Desktop, you can pass credentials to access a remote file using the Web.Contents function to fetch the file. You can include the username and password as part of the request headers. Here's how you can do it:
let
// Define the URL of the remote file
url = "\\path_to_remote\excel.xlsx",
// Define your username and password
username = "YourUsername",
password = "YourPassword",
// Encode the credentials in base64
encodedCredentials = Binary.ToText(Text.ToBinary(username & ":" & password), BinaryEncoding.Base64),
// Create a custom header with the Authorization token
headers = [#"Authorization" = "Basic " & encodedCredentials],
// Fetch the file using Web.Contents with the custom headers
source = Excel.Workbook(
Web.Contents(url, [Headers=headers]),
null,
true
)
in
source
Replace "YourUsername" and "YourPassword" with your actual credentials.
If you find this insightful, please provide a Kudo and accept this as a solution.
Great Solution, Thanks!
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
80 | |
73 | |
52 | |
50 |
User | Count |
---|---|
129 | |
123 | |
78 | |
64 | |
60 |