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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
vetty
Frequent Visitor

user for remote excel sheet

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.

1 ACCEPTED SOLUTION
devesh_gupta
Super User
Super User

@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.

View solution in original post

2 REPLIES 2
devesh_gupta
Super User
Super User

@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!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.