Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Change Data Source from offline excel to SharePoint

Hi all. I am new to PowerBI and have been working in an offline Excel spreadsheet and PowerBI.   I want to upload the Excel and PowerBI to SharePoint so they can be worked on collaboratively. Is th...
  • KNP's avatar
    4 years ago

    If you go into 'Transform data' and look in the advanced editor for your query it will look something like this for local files...

    // Local        
    let
      Source = Excel.Workbook(File.Contents("D:\Downloads\book.xlsx"), null, true),
      Sheet1_Sheet = Source{[Item = "Sheet1", Kind = "Sheet"]}[Data],
      #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars = true]),
      #"Changed Type" = Table.TransformColumnTypes(
        #"Promoted Headers",
        {{"a", Int64.Type}, {"b", Int64.Type}, {"c", Int64.Type}}
      )
    in
      #"Changed Type"

     

    What you need for SharePoint is something that looks like...

    // SharePoint             
    let
      Source = SharePoint.Files(
        "https://youdomain.sharepoint.com/sites/yoursite",
        [ApiVersion = 15]
      ),
      #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "book.xlsx")),
      ExcelFile = #"Filtered Rows"
        {
          [
            Name = "book.xlsx",
            #"Folder Path"
              = "https://yourdomain.sharepoint.com/sites/yoursite/Shared Documents/Data/"
          ]
        }
        [Content],
      #"Imported Excel Workbook" = Excel.Workbook(ExcelFile),
      Sheet1_Sheet = #"Imported Excel Workbook"{[Item = "Sheet1", Kind = "Sheet"]}[Data],
      #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars = true]),
      #"Changed Type" = Table.TransformColumnTypes(
        #"Promoted Headers",
        {{"a", Int64.Type}, {"b", Int64.Type}, {"c", Int64.Type}}
      )
    in
      #"Changed Type"

     

    Essentially, you need to replace the top row of the local one with the top couple of rows of the SharePoint one. Obviously that varies depending on the complexity of your setup.

    Hope that helps.