cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
vetty
Regular 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
Solution Supplier
Solution Supplier

@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
Solution Supplier
Solution Supplier

@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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors