Forum Discussion
JohnHedges
5 years agoFrequent Visitor
Files from a folder - adding columns
Hi, I have three csv files in a folder that Power BI is magically appending as a data source. I want to add a couple of columns to the files, but everything I've tried to add them seems to br...
- 5 years ago
Here is an example that combines all .csv files in C:\temp. It assumes that the files have the same structure, and provides dummy column headers - you may want to provide your own. It also doesn't strip out potentially existing column headers inside the files - you can filter those out if needed, or modify the code for the AddColumn accordingly.
let Source = Folder.Files("C:\Temp"), #"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".csv")), #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Csv.Document([Content])), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6"}) in #"Expanded Custom"
JohnHedges
4 years agoFrequent Visitor
Apologies for not coming back to this discussion sooner - the perils of having too many different projects on the go at once!
Thanks for all the help 🙂