Dan

Dan Evans' Blog

Importing multiple files into Power Query

You can automatically append data from multiple files by choosing to place them in a folder and query the folder. You can choose a folder and it will also search subfolders. You can drop more files into the folder (or remove some) at a later stage, refresh the query and the new files will appear automatically.

image

Once you select From Folder you will be asked to specify the folder location with the option to browse to it.

Once selected, Power Query will find suitable files and list them in the query editor window.

clip_image002

There will be a column named Content. Like the name suggests this is the contents of the file. There are other columns with details of the file like the name, extension and file path. There is also an attributes column that can be expanded to expose more properties.

At the top of the Content column there is a button. If you click this it will import your files and combine them.

clip_image004

However when you use this method, you lose all the information about the files themselves and are left with just the contents. What if you want to use the information about the file? To get around that you can create a custom column like so:

clip_image006

This example is using csv files. Creating this adds a table object into each row of the custom column. From there you can expand the contents alongside the file information.

The same can be done for files stored on SharePoint.

clip_image008

You will be prompted to provide the URL for the SharePoint site. This will be the root URL.

When you do this, a navigator window will open up but your files won’t appear. If you click on the root and click edit you can see why in the query editor.

You’ll notice that the Source query step is in the form of this:

= SharePoint.Tables("https://SharePoint/Site/")

Change this to SharePoint.Files. This will list all the files within the site! Now you can filter this list by file extension or by Folder Path (using the ‘Begins with’ Text Filter), for example.

Loading