Power Query Table.AddColumn: How to Use It
In this article
Table.AddColumn is the Power Query M function that adds a new column to an existing table, filling each row with a value you define. It is the code behind the Custom Column button in Excel and Power BI, and once you understand it you can build calculated columns without touching the graphical menus at all.
What You'll Need
- Excel (with Get & Transform, found on the Data tab) or Power BI Desktop installed
- A table already loaded into Power Query (import a file, or select a range and press Ctrl+T, then use Data > From Table/Range)
- Basic familiarity with the Power Query Editor window
Step-by-Step
- Open your workbook or Power BI report and load your source table into the Power Query Editor. In Excel: Data > From Table/Range. In Power BI: Transform data. Menu labels can differ slightly by version and language.
- Understand the function's signature:
Table.AddColumn(table, name, columnGenerator). The first argument is the table, the second is the new column's name in quotes, and the third is a function that runs once per row, e.g.each [Price] * 1.2. - Open the Advanced Editor (Home > Advanced Editor) so you can see the existing
Sourceand any previous steps. Identify the name of your previous step, such asChanged Type. - Add a new step. The easiest way is to click Custom Column under the Add Column tab, but you can also type directly in the formula bar. The formula bar shows one step at a time; the Advanced Editor shows all steps.
- Type the function call, referencing the previous step name. Example:
Add GST = Table.AddColumn(Changed Type, "Price with GST", each [Price] * 1.1). Note there is no space in Table.AddColumn - it is written exactly that way, unlike the UI button name. - Use the
eachkeyword as shorthand.each [Price] * 1.1means the same as(_)=> _[Price] * 1.1, where the underscore represents the current row. - To reference more than one field in the row, use the full function syntax:
(row) => row[Price] * row[Quantity], or combineeachwith a record:each [Price] * [Quantity]also works because both field references resolve against the same row. - Optionally add a fourth argument for the column type, which helps avoid the “any type” warning later:
Table.AddColumn(Changed Type, "Total", each [Price] * [Qty], type number). - Press Enter (formula bar) or Done (Advanced Editor). The new column appears at the far right of the data preview. Check a few rows against a manual calculation.
- Close & Load (Excel) or Close & Apply (Power BI) to send the results back to the sheet or data model.
Common Mistakes
- Typing the wrong step name as the first argument. The first argument must match a previous step name exactly, including spaces and the leading # if present (e.g.
#"Changed Type"). - Using square brackets in the wrong context.
[Price]works inside aneachbecause the underscore is a record; using it outside that context fails. - Forgetting the
typeargument, then getting unexpected results from filters or sorts because the column is typed as “any”. - Adding the column with Add Column (which keeps the original table) versus Transform tab functions (which replace columns). Table.AddColumn always adds; it never overwrites an existing column.
- Case sensitivity: M is case-sensitive, so
table.addcolumnwill not work - it must beTable.AddColumn.
Tips
- Right-click a step in the Applied Steps list and choose Insert Step After to add your Table.AddColumn call between two existing steps without breaking the chain.
- Name your steps meaningfully in the Advanced Editor (e.g.
AddMargin =) so future-you can read the query. - For conditional logic, combine Table.AddColumn with if/then/else:
each if [Qty] > 100 then "Bulk" else "Standard". - Extract reusable logic into a separate query (right-click > New Query > Blank Query) and call it from the column generator instead of duplicating code.
- Prefer adding columns in Power Query over Excel formulas when the data refreshes - the logic travels with the query.
Troubleshooting
Token Eof expected / Expression.Syntax error: you likely have a missing comma, quote or closing parenthesis. Re-read the line and check the previous step name is spelled correctly.
Expression.Error: The field 'X' of the record wasn't found: the column name inside brackets does not match the table. Field names are case-sensitive - [price] is not [Price]. If the name contains spaces it still works in brackets, but double-check the exact spelling in the preview header.
We cannot convert the value to type Text (or Number): the column contains mixed types. Add a transform before the AddColumn step, or wrap values with Number.From or Text.From, and consider ?. or a null check: if [Price] = null then null else [Price] * 1.1.
Cyclic reference error: the column generator is trying to read the column you are creating. Reference a different, existing column instead.
The new column doesn't appear after loading: confirm the query actually refreshed - in Excel, Data > Refresh All; in Power BI, Refresh. Also check you loaded the query rather than leaving it as Connection Only.
Frequently Asked Questions
What is the difference between Table.AddColumn and the Custom Column button?
Nothing, functionally - the Custom Column button simply writes a Table.AddColumn step for you. Writing it by hand gives you the same result and more control.
Can Table.AddColumn add more than one column at once?
No. It adds exactly one column per call. To add several, chain multiple Table.AddColumn steps, or use Table.ExpandRecordColumn after generating a record.
How do I make the new column appear in a specific position?
Table.AddColumn always appends to the end. Follow it with Table.ReorderColumns to move it, for example Table.ReorderColumns(AddGST, {"Name", "Price with GST", "Price"}).
Why does my new column show “any” as its type?
You omitted the optional fourth argument. Either add type number, type text etc. to the function call, or set the type afterwards with Table.TransformColumnTypes.
Can I use Table.AddColumn on a nested table?
Yes. Add a custom column whose generator is each Table.AddColumn([InnerTable], "New", ...), or expand the nested table first and then add the column.