Power Query Problems

How to Dynamically Clean and Merge Duplicate Columns in Power Query

Steve KSteve K Nov 10, 2026 869 views

Question details

The user needs to dynamically clean column headers, remove generic prefixes, and merge duplicate columns from raw exports (like Jira) without hardcoding every specific column name.

Dynamically Clean and Merge Duplicate Export Columns in Power Query
Product
Excel Power Query
Device & OS
not provided
Scenario
Processing raw data exports that contain messy, dynamic, or duplicate column headers that need to be consolidated dynamically.
Observed behavior
System exports generate multiple duplicate columns with similar data and generic wrapper text (e.g., 'Custom field (FieldName)') that cannot be merged efficiently using static UI steps.
Before you start

Ensure your raw data export is loaded into Power Query. It is highly recommended to duplicate your original query as a backup before applying advanced M code transformations or structural unpivoting.

Solution 1Recommended

Use the Unpivot and Pivot Method to Clean Headers

Unpivoting the data allows you to apply row-level text transformations to your column headers before pivoting them back into a clean, consolidated structure.

This method is highly recommended if you prefer using the Power Query user interface over writing complex M code. By turning columns into rows, you can use standard text extraction tools to clean the headers dynamically.

1
Unpivot Other Columns

Select your static identifier columns (such as 'ID', 'Description', or 'Labels'). Right-click one of the selected column headers and choose 'Unpivot Other Columns'. This will create 'Attribute' and 'Value' columns.

2
Clean the Attribute Column

Select the new 'Attribute' column. Go to the Transform tab, select 'Split Column' > 'By Delimiter', and use the closing parenthesis ')' as your delimiter. Then, use 'Replace Values' to strip out unwanted prefixes like 'Custom field ('.

3
Remove Extra Columns

Delete any leftover columns generated by the split that contain the removed prefixes or suffixes, keeping only the cleaned 'Attribute' column and the 'Value' column.

4
Pivot the Data Back

Select the cleaned 'Attribute' column. Go to the Transform tab and click 'Pivot Column'. In the dialog box, select 'Value' as the Values Column. In the Advanced options, choose not to aggregate if you are dealing with text, or select the appropriate aggregation.

Use the Unpivot and Pivot Method to Clean Headers
Dynamic Updates: Because this method unpivots 'other' columns, it automatically adapts to new or changing custom fields in future data exports without breaking the query.
Free Microsoft Office alternative

Try WPS Office for Your Data Analysis Needs

While advanced Power Query M-scripting is specific to Microsoft Excel, WPS Office provides a lightweight, free alternative that boasts excellent compatibility with Excel formats. It is perfect for handling cleaned datasets, running complex formulas, and creating pivot tables without the burden of a heavy subscription.

  1. 1. Download and Install: Get WPS Office for free from the official website and install it on your device.
  2. 2. Open Your Cleaned Dataset: Launch WPS Spreadsheet and open the .xlsx or .csv file containing your exported data.
  3. 3. Analyze Your Data: Use built-in PivotTables, filters, and advanced functions to extract insights from your consolidated data.
Highly compatible with Microsoft Excel (.xlsx, .csv, .xls) formats without layout distortion.Feature-rich spreadsheets with pivot tables, advanced formulas, and intuitive charting tools.Free to download, lightweight, and uses minimal system resources.Familiar user interface makes migration from Microsoft Office seamless and immediate.
microsoft office alternative - wps office

Frequently Asked Questions

Why should I use List.Accumulate to merge duplicate columns?

List.Accumulate allows Power Query to iterate over a dynamic list of column names, merging them automatically without needing you to hardcode each specific column name. This is ideal for system exports where custom field names or quantities change frequently.

Can I achieve dynamic column renaming without writing custom M code?

Yes. Standard UI features in Power Query usually hardcode column names, but by using the Unpivot method, you convert columns into row values. You can then manipulate these headers using standard UI text tools, and Pivot them back, effectively achieving dynamic renaming with minimal coding.

How do I handle null values when combining duplicate columns dynamically?

When merging columns dynamically in M code, you should wrap your column list in 'List.RemoveNulls(_)' before combining the text. This ensures that empty cells are ignored and your merged text doesn't contain consecutive, unnecessary delimiters.