top of page

You are learning Power Query in MS Excel

How to combine text from multiple columns into a single column in Power Query?

Combining text from multiple columns into a single column in Power Query involves concatenating or merging the values from different columns into a unified string. This is useful for creating composite keys, generating summary descriptions, or preparing data for specific reporting needs. Here’s how you can do it in Power Query:

Method 1: Using the "Add Custom Column" Feature

1. Open Power Query Editor:
- Select `Home` > `Transform Data` to open the Power Query Editor.

2. Add Custom Column:

- Click on the table header or select the columns you want to combine.

- Go to `Add Column` > `Custom Column` from the toolbar.

3. Enter the Concatenation Formula:

- In the "Custom Column" dialog box, provide a name for the new column.

- Use the `&` operator to concatenate text from different columns. For example, to combine `FirstName` and `LastName` into a new column `FullName`:

```m
= Table.AddColumn(#"PreviousStep", "FullName", each [FirstName] & " " & [LastName])
```

- Here, `" "` is used to add a space between `FirstName` and `LastName`. You can adjust the separator as needed (`& "-" &` for a dash, etc.).

4. Load Data:
- After defining the formula, click `OK` and then `Close & Load` to apply the transformation and load the updated data into Power BI or Excel.

Method 2: Using the "Merge Columns" Feature

1. Open Power Query Editor:
- Select `Home` > `Transform Data` to open the Power Query Editor.

2. Merge Columns:

- Select the columns you want to combine (hold `Ctrl` to select multiple columns).

- Go to `Home` > `Merge Queries` > `Merge Columns`.

3. Configure Merge:

- In the "Merge Columns" dialog box, specify the columns to merge, choose a separator if needed, and provide a new column name for the merged result.

- Select an appropriate separator (e.g., space, comma, dash) to separate values from different columns.

4. Load Data:
- Click `OK` to merge the columns, and then `Close & Load` to apply the transformation and load the updated data.

Example: Combining Text from Multiple Columns

Suppose you have a dataset `EmployeeData` with columns `FirstName` and `LastName`. To combine these into a new column `FullName`:

1. Open Power Query Editor:
- Select `Home` > `Transform Data` to open the Power Query Editor.

2. Add Custom Column:

- Go to `Add Column` > `Custom Column`.

- Enter the formula to concatenate `FirstName` and `LastName` with a space:

```m
= Table.AddColumn(EmployeeData, "FullName", each [FirstName] & " " & [LastName])
```

3. Load Data:
- Click `Close & Load` to apply the transformation and load the updated data into Power BI or Excel.

Additional Tips:

- Formatting: Use text functions like `Text.Start`, `Text.End`, or `Text.PadStart` to format text values before concatenation.
- Handling Null Values: Use `Text.Combine` with `List.Select` or `if ... then ... else` to handle null values or empty strings before concatenating.
- Advanced Concatenation: For more complex scenarios, consider creating custom functions or using conditional logic within the concatenation formula.

By utilizing these methods in Power Query, you can efficiently combine text from multiple columns into a single column, making your data more manageable and suitable for various analytical and reporting purposes.

bottom of page