Data Science

How can I use Power Query to automate the cleaning of messy CSV data from multiple sources?

KE Asked by Kevin Adams · 02-11-2023
0 upvotes 16,039 views 0 comments
The question

Every Monday, I spend hours copying and pasting data from five different software exports into one master sheet. I’ve heard Power Query can "record" these cleaning steps. How do I set up a folder-based connection that automatically formats dates and removes duplicates every time I drop a new file into the directory? 

3 answers

0
AM
Answered on 05-01-2023

Power Query is essentially an ETL tool built into Excel. To automate your workflow, go to Data > Get Data > From File > From Folder. Once connected, click "Transform Data." Any steps you take—like Remove Rows > Remove Duplicates or Change Type for dates—are recorded in the "Applied Steps" pane. When you add a new CSV to that folder next Monday, you simply hit "Refresh" in Excel, and Power Query replays those exact steps on the new data. It’s significantly more robust than VBA macros because it doesn't break if the data structure has slight variations or extra empty rows at the bottom. 

0
JA
Answered on 12-01-2023

Are the headers in all five exports identical? If the column names vary even by a single space, Power Query might throw an error during the "Combine Files" step unless you use a custom M-code function. 

C 18-01-2023

James, the headers are mostly the same, but one system uses 'Date' and another uses 'Transaction_Date'. How do I write a simple 'M' script to normalize these column names automatically so the append function doesn't create two separate columns?

0
LI
Answered on 22-01-2023

Once you set up the folder connection, make sure you "Close and Load To" a Pivot Table directly. This saves memory and keeps your workbook from getting too bulky with raw data. 

K 25-01-2023

I agree with Lisa. Loading to the Data Model instead of a worksheet is the best way to handle large datasets. It’s what transformed my reporting from hours to seconds.

Share your thoughts

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

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

World globe icon Country: Canada

Book Free Session