• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Import Multiple Files Containing Multiple Sheets with Power Query

You are here: Home / Power Query / Import Multiple Files Containing Multiple Sheets with Power Query
Import Multiple Files Containing Multiple Sheets with Power Query
April 2, 2020 by Mynda Treacy

In this post we’re going to look at how you can import multiple files containing multiple sheets with Power Query, even if the data isn’t formatted in an Excel Table. In other words, the worst data layout ever!

 

import multiple files containing multiple sheets with power query

The data in these sheets also doesn’t include the date that the data relates to, but thankfully the file name does.

As you can see below, I’ve got three of these terrible files in a folder:

workbooks

Watch the Video

Subscribe YouTube

Download the Files

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download the Excel Workbooks and follow along. Note: This is a .zip file please ensure your browser doesn't change the file extension on download.

Import Multiple Files Containing Multiple Sheets with Power Query

Step 1: Get the data

Data tab > Get Data > From File > From Folder

get the data

Step 2: Select the folder

Click ok and at the folder screen click Transform Data:

select the folder to Import Multiple Files Containing Multiple Sheets with Power Query

Step 3: Remove Other Columns

Hold SHIFT to select the columns containing the meta data that you want to retain, plus the Content column > right-click > Remove other columns. In this example I want to keep the file name (partially hidden behind the right-click menu in the image below) because it contains the date information for the data in each file:

remove other columns

Step 4: Add Custom Column

On the Add Column tab > Custom Column. In the formula field enter the formula shown below:

add custom column

Step 5: Expand the Tables

Click on the double down arrow on the Custom column > click OK:

expand the tables

Step 6: Apply Filters

We can now see a list of the objects in the files (sheets, tables, named ranges etc.). If your files contain tables, sheets or named ranges that you don’t want, use the ‘Kind’ column to filter them out. As you can see in the image below, my files don’t contain any unwanted data:

apply filters

If you click in the white space beside the ‘Table’ in the Custom.Data column, you’ll get a preview of the data in the preview pane at the bottom of the window:

preview pane

Step 7: Remove Unwanted Columns

Before expanding the individual tables in the Custom.Data column, you should remove columns that you don’t want in your final dataset. Note: you must retain the Custom.Data column at the very least!

I want to keep the file name as this contains the date information and the Custom.Name column as this contains the product category information from the worksheet tab names.

remove unwanted columns

Step 8: Expand Tables

Click on the double arrow on the Custom.Data column and deselect the ‘Use original column name as prefix’ check box before clicking OK:

expand tables

Step 9: Promote Headers

You should now see the data from each file and worksheet in one table.

It’s time to tidy up the headers. The first row contains header labels. To promote them, click the drop down in the top left of the table > Use First Row as Headers:

promote headers

Step 10: Rename Columns

Rename the first two columns: File Name and Category. Double click the column header to edit.

Step 11: Remove Extra Header Rows

The headers from the other sheets are still occupying rows in the data set. Click the Product Column filter button and remove ‘Product’ from the list:

remove extra header rows

Extracting Dates from File Names

At this point you may be finished. However, I want to extract the date from the file name, so I have a few more steps to go.

Step 12: Extract the Date from the File Name

The Date column contains the file names, so let’s extract the date from the file name and convert it to a proper date.

Select the File Name column > Transform tab > Extract > First Characters:

extract the date from the file name

I want to discard the .xlsx and keep the first 7 characters:

keep the first 7 characters

Step 13: Split Month and Year

Now I need to split the month and year into separate columns. Select the File Name column > Home tab > Split Column > By Delimiter:

split month and year

In the Split Column by Delimiter dialog box choose the following:

split column by delimiter

You now have the month in File.Name1 and the year in File.Name.2. Power Query should automatically apply a ‘Changed Type’ step to convert these columns to data type; date and you should see it in the Applied Steps pane. If not, select File.Name.1 and File.Name.2 columns > Home tab > Data Type > Whole Number:

changed type

Step 14: Create Date Column

Now we can join the columns back together with a custom column (Add Column >  Custom Column), as a date using the #date function. The syntax is:

create date column

#date( year, month, day)

Notice in the image below that I’ve added 1 for the day value, so all data is as at the first of each month:

Step 15: Remove Columns

Now we can tidy up the columns, deleting File Name.1 and File.Name2 as we don’t need these anymore.

Step 16: Set Data Types

The Sales & Date columns need data types set. Use the drop-down icons to the left of each column header to set the data types:

set data types

Step 17: Rename Query

Lastly, rename the query in the Query Settings Properties with something useful as this will be the Table name in Excel/Power Pivot.

Now you’re ready to Close & Load:

rename query

So, there you have a relatively easy way to import Multiple Files Containing Multiple Sheets with Power Query. There are a lot of steps, but everything is point and click simplicity.

Similar Power Query Scenarios

get data from one file Get data from one file containing multiple sheets

Splitting data over multiple sheets is perhaps one of the worst Excel crimes I see. It’s a crime because it breaks the rule that source data should be in a tabular format. Tabular data is what we need for PivotTables and many functions like SUMIFS, COUNTIFS, INDEX, VLOOKUP etc. However, it’s easily fixed with Power Query.

get data from multiple files

Get data from multiple files containing one sheet

If you receive your data in separate daily, weekly or monthly files then before you can even begin analyzing the data, you need to consolidate it into one table.


Import Multiple Files Containing Multiple Sheets with Power Query

More Power Query Posts

Power Query if Statements incl. Nested ifs, if or, if and

How to write Power Query if statements, including nested if, ‘if or’ and ‘if and’, which are easier to write than their Excel counterparts.
power query variables

Power Query Variables 3 Ways

Power Query Variables enable you to create parameters that can be used repeatedly and they’re easily updated as they’re stored in one place.
delete empty rows and columns using power query

Remove Blank Rows and Columns from Tables in Power Query

Delete blank rows and columns from tables using Power Query. Even rows/columns with spaces, empty strings or non-printing whitespace
extracting data from lists and records in power query

Extracting Data from Nested Lists and Records in Power Query

Learn how to extract data from lists and records in Power Query, including examples where these data structures are nested inside each other.
combine files with different column names in power query

Combine Files With Different Column Names in Power Query

Learn how to load data into Power Query when the column names in your data don't match up. Sampe files to download.
power query keyboard shortcuts

Power Query Keyboard Shortcuts to Save Time

Time saving keyboard shortcuts for Power Query that work in both Excel and Power BI. Download the free Shortcuts eBook
remove text between delimiters power query

Remove Text Between Delimiters – Power Query

Remove all occurrences of text between delimiters. There's no in-built Power Query function to do this, but this code does.
power query advanced editor tips

Tips for Using The Power Query Advanced Editor

Tips for using the Power Query Advanced Editor in Excel and Power BI. Watch the video to see these tips in action
pivot unknown variable number of rows to columns

Pivot an Unknown Number of Rows into Columns

How do you pivot rows to columns when you don't know how many rows you're dealing with? It's not as easy as you may think.
try otherwise power query iferror

IFERROR in Power Query Using TRY OTHERWISE

Using TRY..OTHERWISE in Power Query Replicates Excel's IFERROR So You Can Trap and Manage Errors In Your Queries.


Category: Power Query
Previous Post:project management dashboardExcel Project Management Dashboard
Next Post:Searchable Drop Down List in ExcelSearchable Drop Down List in Excel

Reader Interactions

Comments

  1. Dan

    March 16, 2023 at 1:00 am

    Mynda, excellent tutorial. I have successfully set up a Combine Append query however if any of the source Excel sheets are open the query doesnt pull any of their data in, is there a way around this? Our sheets are simple timesheets, and they are open on operatives’ computers 24/7, but we want to be able to pull the real time data in?

    Thx
    Dan

    Reply
    • Mynda Treacy

      March 16, 2023 at 8:54 am

      Hi Dan,

      There’s no workaround. The files must be closed for Power Query to get the updates. Perhaps an alternative is to have your operatives fill out an Excel Form that deposits the data in an Excel file that you can then connect to with Power Query.

      Mynda

      Reply
  2. Saheed

    June 19, 2022 at 5:54 am

    I am glad to be your student

    Reply
    • Mynda Treacy

      June 19, 2022 at 1:44 pm

      Great to hear, Saheed!

      Reply
  3. Fredrik Johansson

    February 10, 2022 at 11:00 pm

    Hi Mynda Treacy! Try to find a way to use PQ Import Folder (In this folder I have 5 .csv-file (logg files from PLC)) I don’t want to combine, I want them seperate sheets. Is this possible? Or do I need to use PQ import fil choose .csv file and repeat it on all .csv-files?

    Regards Fredrik J

    Reply
    • Mynda Treacy

      February 11, 2022 at 8:55 am

      Hi Fredrik,

      If you want them in separate queries/tables, then you need to get the files one by one using the Get Data > From File > From Text/CSV connector.

      Mynda

      Reply
  4. Stephen

    February 2, 2022 at 4:54 am

    This is goddamn incredible

    Reply
    • Mynda Treacy

      February 2, 2022 at 8:52 am

      So pleased you found it helpful, Stephen! Please spread the word about Power Query 🙂

      Reply
  5. Mike Yantis

    January 30, 2022 at 1:30 am

    Very helpful post Mynda. Thanks for providing the detailed steps and and screenshots.

    Reply
    • Mynda Treacy

      January 30, 2022 at 11:36 am

      Great to hear you found it helpful, Mike!

      Reply
  6. Ian Ripsher

    January 6, 2022 at 4:40 am

    Many thanks, Mynda!

    Reply
  7. Ben Anderson

    April 29, 2021 at 9:06 pm

    Greetings Mynda,

    Thank you so much for all your content and assistance you provide. I do have a question for you regarding the above topic. Let’s for example say you have 6-months of data collected and everything is going great; however, now you notice the dashboard is not updating anymore. After looking into the query you notice those multiple worksheets being combined through power query have all changed format slightly. Is there a way to work around this or do you need to start a new query with the newly formatted names?

    Reply
    • Mynda Treacy

      April 30, 2021 at 9:10 am

      Hi Ben,

      If it’s just a case of names changing then you could copy the M code out of the advanced editor and do a find & replace to fix the changes, then paste it back in.

      Mynda

      Reply
  8. Kevin

    November 19, 2020 at 1:22 am

    Thank you for this tutorial. It was excellent and exactly what I needed. Other sources weren’t even close.

    Reply
    • Mynda Treacy

      November 19, 2020 at 8:53 am

      Pleased to hear that, Kevin!

      Reply
  9. Ghulaam

    October 11, 2020 at 6:06 pm

    Dear Mynda

    Trust you are well, I have viewed your posts randomly be it on you tube or your blog and thank you for the effort you put into explaining the concepts. Keep it up. Regards

    Reply
    • Mynda Treacy

      October 12, 2020 at 8:36 am

      My pleasure, Ghulaam! Glad it was helpful 🙂

      Reply
  10. Raveendra Kumar G

    July 15, 2020 at 6:09 pm

    how to enable tooltips in custom column of excel power query
    Ex: Excel.Workbook([Contetn])
    Here as you type Excel the helper window will appear to select confortably

    Reply
    • Mynda Treacy

      July 15, 2020 at 8:15 pm

      This is a feature available in newer versions of Excel. You’d need to upgrade Excel to get this feature.

      Reply
  11. CHIDOZIE

    June 27, 2020 at 7:33 pm

    I really do not know much about the use of power query. However, watching this video, it seems like the knowledge has been with me all along. Thanks for the very easy way you have put it down for me to understand. Great job Mynda

    Reply
    • Mynda Treacy

      June 28, 2020 at 1:06 pm

      So pleased it was helpful!

      Reply
  12. Joseph

    June 27, 2020 at 4:25 pm

    I’m very surprised for this excellent presentation.

    Reply
    • Mynda Treacy

      June 28, 2020 at 1:06 pm

      Glad you liked it, Joseph!

      Reply
  13. LUIS

    April 3, 2020 at 3:06 am

    Muchas Gracias por tu enseñanza. Te escribo desde Perú.!!!

    Reply
    • Mynda Treacy

      April 3, 2020 at 3:46 pm

      My pleasure, Luis 🙂

      Reply
    • Juan Aguero

      July 24, 2020 at 4:29 am

      Thank you very much Mynda, your tutorials are excellent and you explain so well, step by step. The capabilities of Power Query you are showing are incredible. Great explanation!

      Hope you are your family are very well.

      Greetings from Paraguay, South America

      Reply
      • Mynda Treacy

        July 24, 2020 at 9:29 am

        So pleased we can help, Juan 🙂

        Reply
  14. Jeff

    April 2, 2020 at 11:00 pm

    Hi Mynda. I hope that you and yours are well in these almost surreal times.

    Awesome article and clearly written. When I experience problems with PQ, they most often occur at the very beginning when I load the file, and I suspect I may not be the only one. My initial instinct has always been to expand the “content” column, and that is precisely where I usually become confused. The custom column you add eliminates that problem, but I’m not sure how or why. Do you always do it that way? Can you expand (no pun intended) on that a bit?

    Thank you, we very much appreciate you! Be well and stay safe.

    Reply
    • Mynda Treacy

      April 3, 2020 at 3:48 pm

      Thanks for your kind words, Jeff! By clicking the expand button on the content column, you’re executing the automatic merging of tables. This will only work well if all of the tables are the same format. If any are different, you end up with a mess. I wonder if that’s the cause. You’re welcome to post your question and sample files on our forum and we can take a closer look.

      Reply
  15. jim

    April 2, 2020 at 6:33 pm

    this succinct article would have saved me hours of pain

    I have bookmarked it for future reference

    Reply
    • Mynda Treacy

      April 2, 2020 at 8:52 pm

      Glad it’ll be of use to you, Jim 🙂

      Reply
  16. Chris

    April 2, 2020 at 11:08 am

    Beautifully done! Thank you.

    Reply
    • Mynda Treacy

      April 2, 2020 at 2:01 pm

      Great to know you liked it, Chris 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.