Forum Discussion
JohnHedges
4 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...
- 4 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"
Anonymous
4 years agoNot applicable
Hi JohnHedges,
Did lbendlin 's suggestions help with your scenario? if that is the case, you can consider Kudo or accept his suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng