Smart Systems for Home

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

Power Query Table.CombineColumnsToRecord Guide

· 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

Table.CombineColumnsToRecord is an M function in Power Query that merges several columns into a single column of record values, preserving the original column names as field names inside each record. You need a table with at least two columns and a Power Query editor (Excel, Power BI, or Analysis Services). The function is not exposed as a button in the ribbon, so you will write a small M expression or use the Advanced Editor. The result is useful when you want to keep related fields together, pass structured data to custom functions, or expand the record later into a different shape.

What You'll Need

  • Power Query Editor open on a table or query (Excel: Data > Get Data > Launch Power Query Editor; Power BI: Transform data).
  • A table with at least two columns you want to combine. Column headers must be unique.
  • Basic familiarity with the formula bar or Advanced Editor (Home > Advanced Editor).
  • Optional: a name for the new record column (for example, "Details").

Step-by-Step

  1. Load your data into Power Query. Select your table and open the Power Query Editor. Confirm the columns you want to combine are visible and have the headers you want to become record field names. Rename headers first if needed, because the function uses the current column names.
  2. Decide the columns and the new column name. For example, combine FirstName and LastName into a new column called NameRecord. The function signature is Table.CombineColumnsToRecord(table, newColumnName, sourceColumns, optional options). The sourceColumns argument is a list of column names in curly braces.
  3. Open the Advanced Editor. On the Home tab, click Advanced Editor. You will see the M code for your query. Find the step where your table is named (often Source or ChangedType).
  4. Add a new step. After the last step, add a comma and a new line like this:
    CombinedRecord = Table.CombineColumnsToRecord(PreviousStepName, "NameRecord", {"FirstName", "LastName"})
    Replace PreviousStepName with the actual name of the preceding step. Replace the column names with yours. Keep the quotes and braces exactly.
  5. Update the final in clause. At the bottom of the Advanced Editor, change in PreviousStepName to in CombinedRecord so the query returns the new step.
  6. Click Done. Power Query validates the syntax. If there is an error, it will point to the line. Common causes are a missing comma, a misspelled column name, or using square brackets instead of curly braces.
  7. Inspect the result. The new column shows [Record] in each cell. Click a cell to preview the fields. The original columns are removed by default; if you want to keep them, duplicate the query or add the columns back with a merge if needed.
  8. Expand the record later if required. Click the expand icon (two arrows) in the new column header and choose the fields to bring back as columns. This is useful when you want to reshape the table after combining.

Note: menu labels and the exact location of Advanced Editor can differ slightly by version, device, or region. The M function name and arguments are the same across Excel and Power BI.

Common Mistakes

  • Using square brackets for the column list. The sourceColumns argument must be a list in curly braces: {"A", "B"}, not ["A", "B"].
  • Forgetting to change the in clause. If the last line still points to the old step, the new column will not appear.
  • Column names with spaces or special characters. Quote them exactly as they appear, including spaces: {"First Name", "Last Name"}.
  • Combining columns that do not exist. The function fails if any listed column is missing. Check spelling and case.
  • Expecting a text column. The output is a record, not text. To get text, use Table.CombineColumns with a separator instead.
  • Assuming the original columns remain. By default they are replaced. Plan for that or duplicate the query first.

Tips

  • Rename columns to clean field names before combining; record field names come from the headers.
  • Use the optional options argument only if you need to control how missing values are handled; for most cases the default is fine.
  • If you need to combine many columns, build the list with a variable or use Table.ColumnNames to avoid typing each name.
  • Keep a copy of the query before combining if you may need the original columns later.
  • Records are useful for passing multiple values to custom functions or for JSON export.

Troubleshooting

If the Advanced Editor shows a syntax error, check for a missing comma between steps, unmatched quotes, or a step name that does not match the previous line. If the query loads but the new column is empty, verify the column names in the list match the actual headers exactly. If you see Expression.Error: The column 'X' of the table wasn't found, one of the names is wrong or the column was removed by an earlier step. If the record preview shows unexpected fields, confirm you did not include extra columns in the list. If the query is slow on large tables, combining many columns into records can increase memory use; consider filtering rows first. If the expand icon does not appear, make sure the column type is recognized as Record; you can set it manually in the column type menu. Finally, if you are unsure of the exact step name, click the step in the Applied Steps pane and read the formula bar.

Frequently Asked Questions

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

Table.CombineColumns merges columns into a single text column using a separator you choose. Table.CombineColumnsToRecord merges them into a record value that keeps each original column as a named field.

Can I combine columns with different data types?

Yes. The record fields keep their individual values; the function does not force a single type. You can expand the record later and the original types are preserved.

Does this work in Excel and Power BI?

Yes. The M function is part of the Power Query engine used by both. The editor interface differs slightly, but the function call is the same.

How do I keep the original columns after combining?

Duplicate the query before adding the step, or add the original columns back by merging with the source table. The function itself replaces the listed columns with the new record column.

Can I use a record column in a custom function?

Yes. A record can be passed as a single argument, and you can access fields with [FieldName] inside the function.

Why does my new column show an error instead of a record?

Most often a column name in the list does not match the table, or the previous step name is wrong. Check the step names in the Applied Steps pane and the exact header text.