[Excel/Power Query] Error: Expression.Error — Token Comma Expected (syntax) — How to Fix It

Summary

Expression.Error: Token Comma Expected occurs when Power Query’s M parser detects a missing separator between list, record, or function arguments. It means the code structure is incomplete — a comma is missing between elements or arguments, or parentheses/brackets are unbalanced. Fix it by adding commas in the correct places and verifying that all (), [], and {} are properly matched. Formatting the M code (Ctrl+Shift+F) instantly exposes the faulty line. Applies to Excel 2016+, Microsoft 365, and Power Query for Windows/Mac.

Context

In M language, commas separate items in lists ({}), fields in records ([] or #[…]), and arguments in functions. When a comma is missing, the parser cannot determine where one expression ends and the next begins, so it stops parsing and raises a Token Comma Expected error. This usually happens when manually editing steps in Advanced Editor, copying snippets from other languages like JSON or DAX, or adding function arguments without proper separators. The highlighted position in the editor is often right after the real missing comma.

Probable Cause

  • Missing comma in records or lists. e.g., #[Name="John" Age=30] instead of #[Name="John", Age=30].
  • Incomplete function arguments. Missing separator between parameters in Table.AddColumn, List.Transform, etc.
  • Copied JSON syntax. JSON uses colons (:), but M uses equals (=) and commas between pairs.
  • Unbalanced delimiters. Missing or extra (), [], or {} confuse parser expectations.

Quick Fix

  1. Open the Advanced Editor. Go to Home → Advanced Editor and locate the step causing the error. The cursor will highlight the approximate position.
  2. Format code. Press Ctrl+Shift+F — this auto-indents and visually separates structure blocks.
  3. Insert commas where required. Ensure all record fields and list items are separated.
// ❌ Missing comma between fields
#[Name="John" Age=30]

// ✅ Correct
#[Name="John", Age=30]

// ❌ Missing comma between list elements
{1 2 3}

// ✅ Correct
{1, 2, 3}
  1. Verify function arguments. Check that each argument is separated by commas except the last one.
// ❌ Missing comma before "Net"
Table.AddColumn(Source "Net", each [Amount] - [Tax])

// ✅ Correct
Table.AddColumn(Source, "Net", each [Amount] - [Tax])
  1. Check delimiter balance. Each opening (, [, { must have a closing pair. Nested calls like List.Transform({1,2,3}, each _ * 2) must close correctly.
// ❌ Missing closing parenthesis
List.Transform({1,2,3}, each _ * 2

// ✅ Correct
List.Transform({1,2,3}, each _ * 2)

Full Example

Scenario 1: Record missing comma between fields.

// ❌ Error: Token Comma Expected
Meta = #[Author="Luis" Year=2025]

// ✅ Corrected
Meta = #[Author="Luis", Year=2025]

Scenario 2: List missing commas.

// ❌ Missing comma between numbers
{1 2 3 4}

// ✅ Fixed
{1, 2, 3, 4}

Scenario 3: Function arguments missing separator.

// ❌ Error near 'each'
Table.AddColumn(Source "Net", each [Price] - [Tax], type number)

// ✅ Add missing comma between arguments
Table.AddColumn(Source, "Net", each [Price] - [Tax], type number)

Scenario 4: JSON-style code pasted without proper syntax.

// ❌ JSON syntax (invalid in M)
{ "Name": "John", "Age": 30 }

// ✅ M record syntax
[ Name = "John", Age = 30 ]

Scenario 5: Extra parentheses breaking structure.

// ❌ Parser confused by mismatched ()
= if (x > 10, "High", "Low"))

// ✅ Correct balance
= if (x > 10) then "High" else "Low"

Pitfalls & Debug

  • Symptom → Error points to each. Fix → Look right before it — a missing comma between arguments or fields is likely.
  • Symptom → Error persists after adding commas. Fix → Check for an unmatched (), [], or {}.
  • Symptom → Code copied from JSON/DAX fails. Fix → Replace colons (:) with equals (=), and add commas between fields.
  • Symptom → Advanced Editor refuses to format. Fix → Comment out last edits with // to isolate the faulting line.
  • Symptom → Large record/list definitions break parsing. Fix → Split into smaller variables or build dynamically with Record.Combine or List.Combine.

Validation & Next Steps

After corrections:

// Auto-format for clarity
Ctrl + Shift + F  # (Advanced Editor)

# Validate syntax step-by-step:
1. Disable the last edit temporarily.
2. Refresh preview.
3. Reintroduce code gradually.

When writing manual M code, always format frequently and maintain balanced punctuation. Consider testing expressions in a blank query first before adding them to production queries.

Sources

Power Query M language specification

Table.AddColumn reference

Power Query M function reference

Labels

Tool/Power Query, OS/Cross-platform, Topic/M Syntax & Token Errors