Text Combine Power Query: How to Merge Columns
In this article
To combine text in Power Query, select the columns you want to merge, go to the Add Column or Transform tab, and select Merge Columns. This process allows you to join data from two or more columns into a single string using a custom separator, such as a space, comma, or hyphen, ensuring your data is formatted consistently for reporting or analysis.
What You'll Need
- Microsoft Excel or Power BI Desktop with Power Query installed.
- A dataset loaded into the Power Query Editor.
- Columns that contain text data (or data that can be converted to text).
Step-by-Step
- Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
- Select Your Columns: Click on the header of the first column you wish to combine. To select multiple columns, hold down the Ctrl key and click the headers of the additional columns. The order in which you select the columns determines the order in which the text will be merged.
- Choose Between Transform or Add Column: You have two choices depending on whether you want to keep the original data.
- Transform: If you want to replace the existing columns with the combined version, go to the Transform tab and select Merge Columns.
- Add Column: If you want to keep the original columns and create a new one containing the combined text, go to the Add Column tab and select Merge Columns.
- Configure the Merge Settings: A dialog box will appear. Here, you must define two things:
- Separator: Choose a separator from the dropdown menu. Common options include Space, Comma, Semicolon, or Tab. If you need a specific character not listed, select Custom and type the character (e.g., a dash "-" or a forward slash "/") into the text box.
- New Column Name: Give your combined column a descriptive name, such as "Full Name" or "Complete Address," to ensure your dataset remains organized.
- Apply the Merge: Click OK. Power Query will generate a new step in the Applied Steps pane, and your columns will be combined based on your specifications.
- Verify Data Types: Ensure the resulting column is set to the Text data type. If it is not, click the data type icon next to the column header and select Text.
- Load the Data: Once satisfied, go to the Home tab and select Close & Apply (Power BI) or Close & Load (Excel) to bring the combined data back into your main worksheet or model.
Common Mistakes
One of the most frequent errors is selecting columns in the wrong order. Because Power Query merges text based on the sequence of selection, clicking "Last Name" before "First Name" will result in a "Smith, John" format rather than "John Smith." If this happens, you must delete the Merge step in the Applied Steps pane and restart the selection process.
Another common mistake is attempting to merge columns with different data types, such as merging a Text column with a Date or Number column. While Power Query sometimes handles this automatically, it can often lead to errors or unexpected formatting (such as dates appearing as numbers). To avoid this, manually change the data type of all columns to Text using the type icon in the column header before performing the merge.
Users also frequently forget to name their merged columns. Leaving the default name (e.g., "Merge") can make the dataset confusing as it grows, especially when multiple merges are performed across different tables. Always provide a unique, descriptive name during the merge dialog step.
Finally, over-reliance on the "Transform" option instead of "Add Column" can be a mistake. If you transform the columns, the original source columns are removed from the view. If you later realize you need the original data for a different calculation or filter, you will have to delete the merge step and re-do the process to recover the original columns.
Tips
For more complex combinations that require logic (such as "If column A is empty, use column B"), avoid the standard Merge Columns button and instead use a Custom Column. In the Add Column tab, select Custom Column and use the ampersand (&) operator to concatenate text. For example: [First Name] & " " & [Last Name]. This gives you total control over the output.
If you have null values in your columns, the standard Merge Columns feature handles them gracefully by treating them as empty strings. However, if you use a Custom Column with the & operator, a single null value in any of the columns will cause the entire result to become null. To fix this, use the Text.Combine function in a custom column, as it ignores nulls: Text.Combine({[Column1], [Column2]}, " ").
To clean up your text before merging, use the Trim and Clean functions. Right-click the column header, select Transform, and choose Trim to remove leading and trailing whitespace. This prevents your merged text from having double spaces or awkward gaps if the original data was inconsistently entered.
When dealing with very large datasets, be mindful of the number of steps in your Applied Steps pane. Every merge creates a new step that Power Query must calculate. If you are merging ten different columns, consider if you can group them into a few larger merges to keep the query performance optimal.
Troubleshooting
The result is "Error" instead of text: This usually happens when one of the columns contains a data type that cannot be implicitly converted to text. Check the data types of all columns involved in the merge. If any are set to Whole Number, Decimal, or Date, change them to Text before merging.
The separator isn't appearing: Check if you selected "None" in the separator dropdown. Also, ensure that the columns you are merging actually contain data. If one column is entirely empty (null), the separator may appear to be missing because there is no second piece of text to separate.
The merge order is wrong: Look at the Applied Steps pane on the right. Find the "Merged Columns" step and click the gear icon next to it. While you cannot reorder the columns inside the dialog box, you can delete the step and re-select the columns in the correct order from the grid.
The combined text has strange characters: This is often a result of non-printing characters in the source data. Go to the Transform tab, select the original columns, and use the "Clean" feature to remove non-printable characters before applying the merge.
Frequently Asked Questions
Can I merge more than two columns at once?
Yes, you can select as many columns as you need by holding the Ctrl key. Power Query will merge all selected columns into one, applying the chosen separator between each piece of text.
Does merging columns delete the original data?
It depends on the tab you use. If you use the Transform tab, the original columns are replaced. If you use the Add Column tab, the original columns remain and a new combined column is added to the end of the table.
How do I merge text with a line break instead of a space?
The standard Merge Columns dialog does not have a "Line Break" option. To achieve this, you must create a Custom Column and use Character.FromNumber(10) or Character.FromNumber(13) as your separator in a formula.
What happens if one of the cells is empty (null)?
The Merge Columns tool treats nulls as empty strings, so the separator will still be placed, but there will be no text on one side of it. If you want to avoid double separators, you may need to use the "Replace Values" tool to replace nulls with a blank string first.
Can I merge columns from two different tables?
No, the Merge Columns feature only works on columns within the same table. To combine text from two different tables, you must first use the "Merge Queries" feature to join the tables based on a common key, then use the Merge Columns tool on the resulting expanded table.