Smart Systems for Home

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

Power Query Table.CombineColumns: How to Merge Columns

· 6 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

Table.CombineColumns merges two or more columns into one by applying a combiner function to each row's values. The quickest path: select the columns in Power Query Editor, then go to Transform > Merge Columns, pick a separator, and give the new column a name. That click writes the M code for you. If you need logic the dialog cannot express — conditional separators, null handling, or a custom combiner — you write Table.CombineColumns directly in the formula bar or Advanced Editor. This guide covers both routes, the function's syntax, and the mistakes that cause errors or silent data loss.

What You'll Need

  • Power BI Desktop, Excel (Power Query is built into recent versions), or another host that runs Power Query.
  • A query already loaded with a table that has at least two columns you want to merge.
  • Basic familiarity with the Power Query Editor and the formula bar. M code is case-sensitive, so type function names exactly.

Step-by-Step

  1. Open the query in Power Query Editor. In Power BI Desktop, use Home > Transform data. In Excel, use Data > Get Data > Launch Power Query Editor. Menu labels can differ slightly by version, host, and region.
  2. Select the columns to merge. Click the first column header, then Ctrl+click each additional column. The order you click becomes the order of values in the merged result, so select them deliberately.
  3. Use the built-in merge for simple cases. Go to Transform > Merge Columns. Choose a separator (comma, space, custom, and so on) and type a name for the new column. Click OK. Power Query adds a step and writes the Table.CombineColumns call for you.
  4. Inspect the generated formula. With the new step selected in Applied Steps, look at the formula bar. You will see something like = Table.CombineColumns(PreviousStep, {"FirstName", "LastName"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "FullName"). This is the pattern you adapt when you need custom logic.
  5. Understand the four arguments. The function signature is Table.CombineColumns(table, columnList, combiner, newColumnName). table is the step you are transforming; columnList is a list of column names in curly braces; combiner is a function that receives a list of values and returns one value; newColumnName is the output column name as text.
  6. Write a custom combiner when needed. Replace the combiner argument. For text joined with a dash: Combiner.CombineTextByDelimiter("-", QuoteStyle.None). To keep only non-null values before joining, wrap the list: Combiner.CombineTextByDelimiter(" ", QuoteStyle.None) still passes nulls through as empty text, so filter them first with List.Select(_, each _ <> null) inside a custom function if blanks matter.
  7. Use a custom function for conditional results. The combiner can be any function that takes a list. For example, each Text.Combine(List.Transform(_, Text.From), ", ") converts numbers and dates to text before joining, which avoids type errors when the columns are not all text.
  8. Confirm the data type. After merging, Power Query usually sets the new column to Text. Check the icon in the column header and change it with Transform > Data Type if you need something else. Merged numeric columns become text, so convert back only if the values are truly numeric.
  9. Remove the original columns if desired. Table.CombineColumns already removes the source columns and replaces them with the new one. If you built the step manually and the originals remain, delete them with Home > Remove Columns, or add them to the column list so they are consumed.
  10. Rename and reorder. Double-click the new column header to rename it, or drag it to the position you want. Renaming the step in Applied Steps keeps the query readable.
  11. Check the result and load. Scroll through the preview for nulls, doubled separators, or truncated values. Then use Home > Close & Apply to load the query back to Excel or Power BI.

Common Mistakes

  • Wrong column list syntax. The column list must be a list of text values in curly braces: {"ColA", "ColB"}. Passing a single string or a table instead of a list causes an expression error.
  • Forgetting the combiner is a function. The third argument is not a separator string. Writing Table.CombineColumns(t, {"A","B"}, ",", "New") fails; use Combiner.CombineTextByDelimiter(",", QuoteStyle.None).
  • Nulls becoming empty text. The standard text combiner treats null as an empty string, so a null first name plus a last name yields a leading space. Filter or transform nulls before merging if the output must be clean.
  • Mixing data types. Combining a date or number column with text can raise an error because the combiner expects text. Convert with Text.From first, or use a custom function that transforms each value.
  • Losing the original columns unexpectedly. Table.CombineColumns replaces the listed columns with the new one. If you still need the originals, duplicate them first with Home > Duplicate Column.
  • Case and spelling errors. Column names in the list must match exactly, including spaces and capitalization. A mismatch produces "The column 'X' of the table wasn't found."

Tips

  • Use the Merge Columns dialog to generate correct syntax, then edit the formula bar rather than writing from scratch.
  • Name the step meaningfully (for example "Merge name columns") so the Applied Steps list stays readable.
  • If you merge repeatedly across queries, define a small custom function once and reuse it as the combiner.
  • Keep a duplicate of the source columns when the merged field is for display only; downstream calculations may still need the parts.
  • Test with a row containing nulls and a row with special characters before loading.

Troubleshooting

  • "The column wasn't found": check spelling, capitalization, and whether an earlier step renamed or removed the column. Click the previous step and compare the headers.
  • Expression.Error about a function: the combiner argument is wrong. Confirm you passed a function such as Combiner.CombineTextByDelimiter, not a text value.
  • Unexpected spaces or doubled separators: nulls or empty strings are being joined. Add a filtering step or a custom combiner that removes blanks.
  • Values look truncated: the column may have a data type that limits length, or a later step is splitting the text. Check the steps after the merge.
  • Numbers show as text: this is expected after merging. Change the data type only if every value is genuinely numeric; otherwise keep it as text.
  • If that did not work: delete the merge step, re-select the columns, and redo it through Transform > Merge Columns to regenerate valid code. Then modify one argument at a time and refresh the preview after each change.

Frequently Asked Questions

What is the difference between Table.CombineColumns and Table.AddColumn?

Table.CombineColumns replaces the selected columns with one merged column. Table.AddColumn keeps the originals and adds a new column, so use it when you need both the parts and the combined value.

Can I merge more than two columns?

Yes. List every column name in the columnList argument, in the order you want the values joined.

How do I skip null values when merging?

Use a custom combiner that filters the list first, for example a function that applies List.Select to remove nulls before Text.Combine. The built-in delimiter combiner does not skip nulls.

Does Table.CombineColumns work in Excel Power Query?

Yes. The function is part of the M language used by Power Query in both Excel and Power BI, so the same syntax applies.

Why did my merged column become text?

Combining values produces a single text result by design. Change the data type afterward if the merged values are all numbers or dates.

Can I use a custom separator like a line break?

Yes. Pass the character sequence to Combiner.CombineTextByDelimiter, for example "#(lf)" for a line feed, or use a custom function for more complex formatting.