In a recent blog post, I described the process required to combine multiple sheets into one single table using PowerQuery. Shortly after posting this, the Power Query guru Wyn Hopkins pointed out an alternative method that makes the process more efficient which I wasn’t aware of.
Note - If you've not checked out Wyn's PowerQuery content you're missing out, check out his YouTube Channel here and his podcast 'Power Query Magic' which is available on all good podcast platforms.
When connecting to multiple sources in PowerQuery, you'll often be presented with the option to combine files. The Content column below displays the combine icon which consists of two down arrows and a single line across the bottom of the button.
Clicking the 'combine files' button presents the 'Combine Files' window which provides a number of options.
At first glance, it might seem that combining both sheets in the example below is not possible as there is no way of ticking both items. Fortunately, this isn't the case as there is an additional option that isn't immediately obvious that Wyn kindly pointed out.
The advice I received from Wyn is to right-click on the parent element in the 'Display Options' section of the window presents an additional option titled 'Transform Data' which will load all the elements displayed under the parent element. In this case, both sheets from an excel file. It's amazing to think that this functionality exists behind a menu that I'd bet the majority of PowerQuery users would never think to try! There isn't even an ellipsis to suggest there is a menu!
Once initiated the result is a list of all the elements in all the items that have been combined. Here this is 3 excel files, all containing 2 sheets.
Note - As the contents of the items to combine contain a column titled 'Name' the process has removed the file metadata which also included a column titled 'Name'. To resolve this, go back a few steps until the filename appears, rename the column titled 'Name' to something other than Name (i.e. FileName) and then delete the step that removed the columns and the filename will appear in the final table. If the 'Content' column is not required, remove it as required.
Most scenarios will only need the 'Filename' and the 'Data' columns to proceed. If this is the case, remove all the other columns until you're presented with a table similar to the one below
Click the 'Expand' icon next to the Data column header to expand the data.
The result will be a combined table containing the contents of all the sheets from all the files
Comments
Post a Comment