Reputation: 768
I have an xlsm
file in a parent folder, and I want to import whatever CSV file is in a child folder regardless of its label
I want to use the relative path of the xlsm file to do this
I am trying:
FP = ChDir (CurrentProject.Path) & "\SourceData\"&"*.csv",
Source = Csv.Document(File.Contents(FP),[Delimiter=",", Columns=18, Encoding=1252, QuoteStyle=QuoteStyle.None])
But I am getting the error:
Expression.Error: The name 'ChDir' wasn't recognized. Make sure it's spelled correctly.
What is the best way to do this?
Thanks
Upvotes: 0
Views: 243
Reputation: 21318
this combines all the CSV files in the parent and subdirectories
You can modify as needed
let Source = Folder.Files("C:\directory"),
#"Filtered Rows" = Table.SelectRows(Source, each [Extension] = ".csv"),
#"Added CSVdata" = Table.AddColumn(#"Filtered Rows", "CSVdata", each Table.PromoteHeaders(Csv.Document([Content])), type table),
#"Added Custom" = Table.AddColumn(#"Added CSVdata", "Custom", each let name = [Name] in Table.AddColumn([CSVdata],"SourceFile", each name)),
#"Combined CSVdata" = Table.Combine(#"Added Custom"[Custom])
in #"Combined CSVdata"
Upvotes: 1