Loading Mulitple CSV filenames

qlander

New Member
Joined
Dec 26, 2018
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
Hello there,

Although this is predominatley a Power Query Question, the criteria are obtained from an Excel Sheet and the output placed on 1 Excel sheet.

I have some PQ code (Windows Excel 2016) that will load a single pre-specified CVS file into Excel as follows:

Excel Sheet1:
Excel Name (Cell contents found in in A1): FilePath = C:\Users\Public\Documents\Data\
Excel Name (Cell contents found in in A2): Filename = James1.csv

Power Query Code
:
Power Query:
let
    FilePath = Excel.CurrentWorkbook(){[Name="FilePath"]}[Content]{0}[Column1],
    FileName = Excel.CurrentWorkbook(){[Name="FileName"]}[Content]{0}[Column1],
    Source = Csv.Document(File.Contents(FilePath & FileName))


in
    Source

This works perfectly fine for just the 1 dynamically named file. Changing the filename in the Excel Sheet also changes the data dynamically.

However, I am a little lost when trying to use multiple pre-specified file names in the same manner using the excel sheet...

eg if the Filenames were "James1,csv", John2.csv", Andrew1,csv", etc... all in the same FilePath and all re-definable via the spreadsheet cells A3,A4,A5, etc...(ie not in the PQ code) and assuming the data within each CSV is consistant (ie same columns), what PQ code could be used ot load each one on the same sheet?

Is there a way to define filenames (plural) to automatically load them into 1 sheet using Power Query? (unable to use any macros due to security settings).

Thanks
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top