Power Query Problems

How to Prevent Power Query from Removing a Blank First Column in Excel

Olivia MillerOlivia Miller Nov 10, 2026 869 views

Question details

Users need a way to stop Power Query from automatically dropping blank columns before the first populated column when combining files.

How to Prevent Power Query from Removing a Blank First Column in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Combining multiple CSV or Excel files where some files have an entirely blank first column, causing data misalignment.
Observed behavior
Power Query drops the blank first column during combination, shifting subsequent column names to the left and causing data to misalign when files are appended.
Before you start

Verify the exact number of expected columns across all your source files and open the Advanced Editor in Power Query to prepare for M-code adjustments.

Solution 1Recommended

Use Advanced Editor to Dynamically Adjust Column Names

Modify the Transform Sample File query using M code to detect missing columns and shift column names accordingly to ensure alignment.

By default, Power Query's Csv.Document function relies on the first sample file to set options, including the number of columns. If a subsequent file has a blank first column, Power Query drops it, shifting all data to the left.

You can adjust the M code to evaluate the column count dynamically. If a file has fewer visible columns, the query will shift the column names so that everything aligns correctly during the final combination.

1
Open the Transform Sample File query

In the Power Query Editor, locate the 'Transform Sample File' query in the left Queries pane, right-click it, and select 'Advanced Editor'.

2
Remove the hardcoded columns limit

Find the 'Source = Csv.Document(...)' line and remove the 'Columns=X' parameter so it does not strictly force the sample file's column count on every subsequent file.

3
Add column alignment logic

Define your expected number of columns (e.g., NumberOfColumns = 4) and use 'Table.ColumnCount' to check the incoming file. Create a condition: if the count is less than expected, use 'Table.RenameColumns' to shift the names (e.g., renaming Column 1 to Column 2).

4
Save and close the Advanced Editor

Click 'Done' in the Advanced Editor. The appended query will now align files by their adjusted column names instead of simply stacking shifted data.

Use Advanced Editor to Dynamically Adjust Column Names
Important: Ensure you replace the 'NumberOfColumns' variable in your M code with the actual expected total number of columns for your dataset.
Free Microsoft Office alternative

Edit and Manage Your Data Easily with WPS Office

While complex M-code scripts and Power Query functionalities are native to Microsoft Excel, WPS Office offers a free, lightweight, and highly compatible alternative for standard data processing, filtering, and spreadsheet management.

Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv)Lightweight software with an incredibly fast installation processFamiliar user interface requiring no learning curvePowerful built-in data filtering, sorting, and pivot table tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does Power Query remove blank columns automatically?

Power Query attempts to optimize data by removing columns that appear entirely empty. When combining files, it relies on the first sample file's structure. If subsequent files differ or have leading blank columns, the automatic detection fails to align them correctly.

Can I fix column alignment without writing M code?

Yes. You can load your files into separate individual queries, manually add or delete columns so that all queries have the exact same structure and column names, and then use the 'Append Queries' feature to combine them.

How do I specify the expected number of columns in Csv.Document?

You can open the Advanced Editor and manually add or adjust the 'Columns' parameter inside the Csv.Document function. For example: Csv.Document(Source, [Delimiter=",", Columns=5, Encoding=65001]).