[Excel/Power Query] Error: Expression.Error — Token RightBrace Expected (missing “}”) — How to Fix It

Summary

Expression.Error: Token RightBrace Expected means Power Query’s M parser detected an opening brace { or record start #[ without the corresponding closing }. This typically occurs in list definitions, record literals, or nested constructs edited manually. The error halts parsing before the structure completes. Fix it by locating the unmatched brace, ensuring all lists {} and records #{[]} are closed properly, and removing stray commas or mixed syntax. Formatting (Ctrl+Shift+F) exposes structural mismatches instantly.

Context

M uses braces for two major structures: lists ({1,2,3}) and records (#[Field1=Value1, Field2=Value2]). In nested formulas—such as Table.FromRecords or List.Transform—it’s easy to drop a brace when pasting or commenting code. Unlike Excel formulas, M doesn’t autocorrect or close braces automatically, so one missing } can invalidate an entire step. The parser typically flags the end of the file or the next keyword (in, each, etc.) as the problem area, even though the missing brace occurred earlier.

Probable Cause

  • Missing closing brace in a list. Example: {1, 2, 3 without }.
  • Record literal not closed. Example: #[Name="Luis", Year=2025 missing }.
  • Trailing comma before closing. Example: #[A=1, B=2, }.
  • Copy-paste truncation. Code snippets losing last character during edits.
  • Incorrect nesting. Mixing list and record syntax, e.g., {#["Name"="John"]}.

Quick Fix

  1. Open Advanced Editor. Home → Advanced Editor. Scroll to the bottom; Power Query usually highlights near the missing closure.
  2. Format the code. Use Ctrl+Shift+F — indentation will clearly show unmatched braces.
  3. Balance all structures. For each opening brace { or #[, ensure one matching }.
  4. Remove trailing commas. The last element in a list or record must not end with a comma.
  5. Rebuild truncated literals. If part of a record or list was deleted, reconstruct it manually and reapply transformations step by step.
// ❌ Missing closing brace in list
let
  Values = {1, 2, 3
in
  Values

// ✅ Fixed
let
  Values = {1, 2, 3}
in
  Values
// ❌ Missing brace in record
let
  Info = #[Name="Luis", Year=2025
in
  Info

// ✅ Corrected
let
  Info = #[Name="Luis", Year=2025]
in
  Info
// ❌ Trailing comma before closing
let
  Record = #[A=1, B=2, }
in
  Record

// ✅ Remove trailing comma
let
  Record = #[A=1, B=2]
in
  Record

Full Example

Scenario 1: List structure truncated during manual edit.

// ❌ Error: Token RightBrace Expected near end of input
let
  MyList = { "A", "B", "C"
in
  MyList

Fix: Add the missing closing brace.

// ✅ Corrected
let
  MyList = { "A", "B", "C" }
in
  MyList

Scenario 2: Record copied from another query missing closure.

// ❌ Error when defining record
let
  Metadata = #[
      Source="Dataset",
      Version="1.0",
      Date="2025-10-16"
in
  Metadata

Fix: Add closing ] and ensure no trailing commas.

// ✅ Balanced record
let
  Metadata = #[
      Source="Dataset",
      Version="1.0",
      Date="2025-10-16"
  ]
in
  Metadata

Scenario 3: Nested braces mixed between record and list.

// ❌ Invalid combination
let
  Invalid = {#["Name"="John", "Age"=30]}
in
  Invalid

// ✅ Correct version — record inside list must be standalone
let
  Fixed = { [Name="John", Age=30] }
in
  Fixed

Pitfalls & Debug

  • Symptom → EOF or “unexpected end” error. Fix → A list or record block never closed — search for unpaired { or #[.
  • Symptom → Error near in. Fix → The closing } or ] is missing before the in statement.
  • Symptom → Formatting looks unaligned. Fix → Reformat and inspect indentation; mismatched levels signal an open brace.
  • Symptom → Nested objects collapse unpredictably. Fix → Convert sections into separate let-bindings to isolate where the missing brace occurs.
  • Symptom → Using {#[]} hybrid constructs. Fix → Avoid mixing list and record syntaxes; wrap one inside the other explicitly.

Validation & Next Steps

After balancing braces, format (Ctrl+Shift+F), confirm indentation is consistent, and refresh the query. When constructing long record or list literals, prefer vertical layouts:

#[ 
    A = 1,
    B = 2,
    C = 3
]

This makes unmatched braces and commas visually obvious. For large transformations, modularize: keep list or record definitions in separate variables before applying transformations like Table.FromRecords or List.Transform.

Sources

Power Query M language specification

Record Type Reference

List Functions

Labels

Tool/Power Query, OS/Cross-platform, Topic/M Syntax & Brace Matching