How to quickly fix CSV files in Excel using Power Query


Web apps love exporting CSV files, but they don’t always play nice with Excel. Leading zeros disappear, dates break, and text fields merge together. Most people waste time fixing these problems manually, even though Excel includes a built-in Power Query tool that automatically cleans and reshapes messy data in seconds.

This article uses two sample CSV files: Sales_Report_January.csv and Sales_Report_February.csv. When you open the links, you can download the files for free by clicking the download button in the top-right corner of your screen. Once downloaded, move both files to a new, dedicated folder on your computer.

Power Query tames messy CSV files instantly

Fixing broken data automatically

Illustration with Excel and Power Query (PQ) icons, a data table grid, a circular chart, and a cylinder shape. Credit: Lucas Gouveia/How-To Geek

The secret to effortless file cleanup is Power Query, Microsoft’s tool for importing and reshaping data in Excel. Think of it as a built-in data cleaning engine that handles the tedious work for you. Instead of fixing errors cell by cell in a worksheet, you define steps in a separate editing window. Your original CSV stays untouched because Power Query only imports and transforms a copy.

Power Query saves your transformations as reusable steps that run again whenever you refresh the query. Because it remembers everything you do, future imports with the same layout can be updated by simply clicking Data > Refresh All. Excel then automatically reapplies all your steps, eliminating repetitive CSV cleanup from your workflow.


Graphic featuring Excel and Power Query logos alongside a database and bar charts.


You don’t need VBA to auto-refresh your Power Queries in Excel

Stop relying on manual clicks and clunky code—let Excel refresh your queries automatically.

Step 1: Import your CSV files into Excel the smart way

Starting with the right import process

To clean up your files properly, you need to import them through Excel’s data tools instead of simply double-clicking the CSV file.

To follow along in this section, use the above-linked Sales_Report_January.csv file.

Here’s the workflow:

  1. Open a blank workbook and go to the Data tab.
  2. Click Get Data > From File > From Text/CSV.
  3. Locate and select the CSV file, then click Import.
  4. Review the preview window to make sure Excel has correctly detected the delimiter (usually a comma). If the data is not properly split into columns, change the delimiter.
  5. Click Transform Data.

This opens the Power Query Editor workspace where all cleaning happens before the data reaches Excel.

Step 2: Clean up CSV formatting with a few clicks

Scrubbing the junk

Once the Power Query Editor opens, you can start fixing the issues that usually make raw CSV files difficult to work with.

This section continues from the previous step, so you should still be working with the imported Sales_Report_January.csv file.

Here are some of the most useful cleanup actions you can perform:

Split full names

  1. Right-click the Full Name column.
  2. Choose Split Column > By Delimiter.
  3. Choose Space to separate the column into first and last names, and click OK.
  4. Double-click the new column headers to rename them.

Fix inconsistent date formats

Click the data type icon in the Order Date column header and set it to Date.

Because this column contains mixed date formats (US, EU, and text-based), Power Query may not interpret every value correctly. As a result, some cells in this column will show Error, while the rest of the row remains intact.

Don’t try to fix every invalid date manually. Keep the dataset usable and continue cleaning other fields first. You can handle or filter invalid dates later during analysis or reporting.

OS

Windows, macOS, iPhone, iPad, Android

Free trial

1 month

Microsoft 365 includes access to Office apps like Word, Excel, and PowerPoint on up to five devices, 1 TB of OneDrive storage, and more.


Preserve ZIP codes and product IDs

If ZIP codes like 02138 or Product IDs like 000245 lose leading zeros, Power Query has likely inferred a numeric type during the automatic Changed Type step.

To fix this:

  1. In the Applied Steps pane, select the first Changed Type step.
  2. Click the data type icon in the relevant column headers and select Text.
  3. If prompted, click Insert to add the intermediate step.
  4. Finally, click Replace current to update the existing step instead of creating a new one.

The leading zeros are now preserved correctly when the data is loaded into Excel.

Remove unnecessary columns

To keep the dataset focused on useful fields like customer, order, and product data:

  1. Hold Ctrl while selecting the Region and Internal Notes columns.
  2. Right-click one of the selected columns and choose Remove Columns.

Load the cleaned dataset

Once you’re happy with how your data looks, click Close & Load in the Home tab to load the cleaned Sales_Report_January.csv into Excel as a structured table.

At this point, you’ve turned a messy raw CSV into something usable in seconds.


Excel logo with a spreadsheet in the background, some charts around it, and 'Power Query' written.


5 everyday actions that Power Query does better than regular Excel tools

Replace manual Excel tasks with conditional columns, smart merging, the unpivot tool, and more.

Pro tip: Combine multiple CSV reports into a single sheet

Automating repetitive merges

Instead of repeating cleanup steps, Power Query can apply the same transformation logic across multiple CSV files in a folder.

This section starts a new workflow using both the original Sales_Report_January.csv and Sales_Report_February.csv files, so double-check that they’re saved in the same folder before you start. Because this is a new workbook and a new query, your earlier single-file cleanup work won’t carry over.

First, follow these steps to connect Excel to the folder containing your reports:

  1. In a new Excel workbook, click Data > Get Data > From File > From Folder.
  2. Select the dedicated folder containing both CSV files.
  3. Click Open.

This tells Excel to treat every CSV in the folder as part of a single combined table.

Next, define how the combined data should be structured:

  1. Click Combine > Combine & Transform Data.
  2. Choose the file you want to act as the sample file—usually the first or most complete report—and make sure the correct delimiter is selected (usually a comma) so that the columns are correctly separated.
  3. Click OK.
  4. In the Power Query Editor, review the combined data and perform additional cleanup if needed.
  5. Click Close & Load in the Home tab to send the combined, cleaned report to a new Excel worksheet.

From here, whenever you drop new files into the folder, just click Data > Refresh All to update the query.

The top half of the split Refresh All button in Excel's Data tab is selected.


The automated analytics advantage

Power Query handles two of the hardest parts of working with spreadsheet data: cleaning messy CSV imports and turning them into structured tables for analysis. It helps you spend less time preparing information and more time working with it—and crucially, it’s one of the main reasons many people prefer Excel to Google Sheets and open-source alternatives.



Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


Ahead of WWDC starting on June 8, Apple has sent out invites to the media for the event, as well as outlining its main schedule for the week.

Apple’s Worldwide Developer Conference is the big event for developers working in the Apple ecosystem. The 2026 edition is sure to be exciting as usual, and the company is preparing to get people involved.

On Monday, Apple started sending out invitations to members of the media to attend a special event at Apple Park. While this would previously have involved watching a live keynote, it has since taken the form of a mass viewing of the keynote at Apple’s headquarters, along with special events for attendees.

The tagline for the event this time is “Coming bright up.” As usual, it is a cryptic statement, providing little clue about what Apple will ultimately reveal to the world.

A schedule to follow

At the same time as sending out invitations, Apple has also listed the events that will take part across the week. It also outlined how developers can observe and take part in events remotely.

The week starts with the Apple Keynote on June 8 at 10 a.m. PDT, which will be the venue for Apple’s main launches, such as iOS 27. The keynote will stream from Apple’s website, the Apple TV app, and the Apple YouTube channel.

At 1 p.m. later that day, the Platforms State of the Union will be a deeper dive into new features, APIs, and technologies that are on the way. It will be viewable from the Apple Developer app, website, YouTube channel, and Bilibili.

Throughout the week, Apple will be holding video sessions and releasing guides, hosted by Apple engineers and designers. Group Labs, consisting of live online presentations and Q&A sessions, will also take place from Tuesday through Friday.

There will also be the Apple Design Awards, with 36 finalists chosen to highlight the craft, creativity, and technical expertise of the developer community.



Source link