Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Concat: How to Merge Columns and Text

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To concatenate in Power Query, the fastest method is to select the columns you want to combine, go to the Add Column or Transform tab, and select Merge Columns. This allows you to choose a separator (like a space or comma) and name your new combined column without writing any code.

Concatenation is the process of joining two or more strings of text into one. In Power Query, this is essential for creating full names from first and last name columns, generating unique IDs by combining dates and codes, or formatting addresses for reporting. Because Power Query is strictly typed, you must ensure all columns being merged are set to the "Text" data type, or the operation will result in an error.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • A dataset loaded into the Power Query Editor.
  • Columns containing the text you wish to combine.

Step-by-Step

  1. Open Power Query Editor: In Excel, go to the Data tab and select Get Data or Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
  2. Set Data Types to Text: This is the most critical step. Select the columns you intend to concatenate. Right-click the column header, select Change Type, and choose Text. If you try to concatenate a number or a date without converting it to text first, Power Query will return an error.
  3. Select Your Columns: Hold the Ctrl key and click the headers of the columns you want to merge. The order in which you select them is the order in which the text will appear in the final result.
  4. Choose Merge Method:
    • To keep the original columns: Navigate to the Add Column tab and click Merge Columns. This creates a brand new column at the end of your table.
    • To replace the original columns: Navigate to the Transform tab and click Merge Columns. This combines the data and removes the source columns.
  5. Configure Merge Settings: A dialog box will appear.
    • Separator: Choose a separator from the dropdown (e.g., Space, Comma, Semicolon) or select --Custom-- to type your own character.
    • New column name: Type a descriptive name for your combined column (e.g., "Full Name" or "Unique ID").
  6. Apply and Close: Click OK. You will see the new concatenated column in your preview. Click Close & Apply (Power BI) or Close & Load (Excel) to bring the data back into your worksheet or model.

Common Mistakes

  • Merging Non-Text Columns: The most common error is attempting to merge a "Whole Number" or "Date" column. Power Query cannot "add" text to a number. You must explicitly change the type to Text first.
  • Wrong Selection Order: If you select "Last Name" and then "First Name," your result will be "Smith, John" instead of "John Smith." You must select the columns in the exact sequence you want them to appear.
  • Overlooking Nulls: If one of the columns contains a null value, the entire concatenated result for that row may become null depending on the method used.
  • Using Transform instead of Add Column: Users often accidentally use the Transform tab, which deletes their original source columns. If you need the original data for other calculations, always use the Add Column tab.

Tips

  • Custom Delimiters: If you need a line break as a separator, you cannot simply press Enter in the Custom separator box. Instead, use a Custom Column and the formula [Column1] & "#(cr)#(lf)" & [Column2].
  • Using the Ampersand (&): For more complex concatenations (like adding static text), go to Add Column > Custom Column. You can use the & symbol to join text. For example: "ID: " & [EmployeeID] & " - " & [LastName].
  • Trimming White Space: Before concatenating, it is a good practice to right-click your columns and select Transform > Trim. This removes accidental leading or trailing spaces that can make your merged text look messy.

Troubleshooting

If your concatenation does not go to plan, try these steps in order:

  1. Check for "Expression.Error": If you see an error in the cells, check the data types. Ensure every column involved in the merge is set to Text.
  2. Handle Null Values: If the result is null because one source cell was empty, use the Replace Values feature. Right-click the column, select Replace Values, and replace null with an empty string (leave the "Replace With" box completely blank).
  3. Verify Selection Order: If the text is in the wrong order, delete the "Merged Columns" step in the Applied Steps pane on the right and re-do the selection process.
  4. Refresh Preview: If the changes aren't appearing, ensure you haven't accidentally filtered the data in a previous step that is hiding the rows you are looking for.

Frequently Asked Questions

Can I concatenate more than two columns?

Yes. You can select as many columns as you need by holding the Ctrl key. Power Query will merge all selected columns using the chosen separator.

How do I add a space between merged columns?

In the Merge Columns dialog box, click the Separator dropdown menu and select Space. This will automatically insert one space between each merged value.

Why is my merged column showing as "null" for some rows?

In Power Query, any operation involving a null value often results in null. To fix this, replace the null values in your source columns with an empty string before merging.

Is there a way to concatenate without creating a new column?

Yes. Use the Merge Columns option found under the Transform tab. This will overwrite the selected columns with the combined result.

Can I use a formula instead of the Merge tool?

Yes. You can create a Custom Column and use the & operator (e.g., [First] & " " & [Last]). This provides more flexibility for adding custom text or conditional logic.