Forum Discussion
Nathaniel_C
3 years agoCommunity Champion
Using a path name from an SQL query to open a csv file in power query
Hello,
Helping a colleague with this project.
The colleague has created a SQL query that finds the path to a csv file. This path changes on a daily basis, so we need to have the path refre...
ImkeF
3 years agoCommunity Champion
Hi Nathaniel_C ,
if the content is all on one site, this is a possible approach (FilePath is the parameter with the full path to the file on SP):
let
Source = SharePoint.Files("https://<<YourDomainHere>>.sharepoint.com/sites/<<YourSiteNameHere>>", [ApiVersion = 15]),
#"Inserted Merged Column" = Table.AddColumn(Source, "fullPath", each Text.Combine({[Folder Path], [Name]}, ""), type text),
#"Filtered Rows" = Table.SelectRows(#"Inserted Merged Column", each ([fullPath] = FilePath)),
#"Content 1" = #"Filtered Rows"{0}[Content],
#"Imported Excel Workbook" = Excel.Workbook(#"Content 1")
in
#"Imported Excel Workbook"
For different sites, I don't know an approach that wouldn't trigger dynamic datasource error.
edit: Actually, this might be faster:
let
Source = SharePoint.Contents("https://<<YourDomainHere>>.sharepoint.com/sites/<<YourSiteName>>", [ApiVersion = 15]),
Documents = Source{[Name="Shared Documents"]}[Content],
#"Filtered Rows1" = Table.SelectRows(Documents, each ([Name] <> "Forms")),
#"Expanded Content" = Table.ExpandTableColumn(#"Filtered Rows1", "Content", {"Content", "Name", "Extension", "Folder Path"}, {"Content.1", "Name.1", "Extension.1", "Folder Path.1"}),
#"Inserted Merged Column" = Table.AddColumn(#"Expanded Content", "fullPath", each Text.Combine({[Folder Path.1], [Name.1]}, ""), type text),
#"Filtered Rows" = Table.SelectRows(#"Inserted Merged Column", each ([fullPath] = FilePath)),
#"Content 1" = #"Filtered Rows"{0}[Content.1],
#"Imported Excel Workbook" = Excel.Workbook(#"Content 1")
in
#"Imported Excel Workbook"Nathaniel_C
3 years agoCommunity Champion