How to Automate CSV File Transformations with Power Query in Excel
Question details
The user needs to automate the removal of extra columns and clean up CSV exports so the transformation can be reused for future files before importing them into an accounting program.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Preparing and cleaning recurring CSV exports for an accounting system.
- Observed behavior
- The user wants to save a specific sequence of data cleaning transformations and apply them automatically to new CSV exports without having to recreate the process each time.
Ensure that your future CSV exports will maintain the exact same column structure and header names as the original file, as Power Query relies on these to apply your saved transformations correctly.
Build a Reusable Power Query by Overwriting the Source File
Create the transformation steps once on a base CSV file, and simply replace that file with new data in the future.
The easiest way to reuse a query is to keep the file path and file name of your source data constant. By replacing the old CSV file with the newly exported CSV file, Power Query can execute all recorded steps on the fresh dataset instantly.
In Excel, navigate to the Data tab, click 'Get Data', choose 'From File', and then 'From Text/CSV'. Select your initial CSV export and click 'Transform Data'.
In the Power Query Editor, remove the unwanted extra columns, change data types for your accounting import, and click 'Close & Load' to save the query into your workbook.
When you receive a new CSV export, rename it to exactly match the original file's name. Move it into the same folder, overwriting the old file.
Open your Excel workbook containing the saved query, go to the Data tab, and click 'Refresh All'. The new CSV data will automatically be transformed according to your saved steps.

Process Multiple CSV Files Automatically from a Folder
If you want to keep historical files and automatically transform any new CSV added to a specific directory.
Looking for a Lightweight Alternative for Data Processing?
If you find Microsoft Excel's Power Query too complex or simply need an accessible, affordable tool for daily data management, consider WPS Office. It provides a highly compatible spreadsheet tool that makes handling CSV files, organizing data, and performing daily calculations completely free and intuitive.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device in minutes.
- 2. Open your CSV Files: Launch WPS Spreadsheets and open your CSV exports directly with perfect layout retention.
- 3. Process and Save: Use built-in data tools to clean your spreadsheets and save them in widely accepted formats like .xlsx.

Frequently Asked Questions
Can I apply my Power Query transformation to a CSV file with a different name?
Yes, but you must manually update the source. Open the Power Query Editor, click on 'Data Source Settings', select 'Change Source', and browse for the newly named CSV file. To avoid this step, it is easier to overwrite the original file with the new data using the same name.
Why does my query fail when I refresh with new CSV data?
Errors usually occur if the new CSV file has different column headers, a different delimiter, or missing columns compared to the original file used to build the query. Power Query expects a consistent data structure.
Can I copy my Power Query steps to another Excel workbook?
Yes. Open the Power Query Editor, go to the Home tab, and click 'Advanced Editor'. Copy the entire M code text, open a blank query in your new workbook, and paste the code there.




