Expression.Error: There is an extra comma in the query code.

In Power Query, Expression.Error: There is an extra comma in the query code. occurs when an M-code statement contains an invalid trailing comma, an empty parameter separator, or a comma immediately preceding the in keyword.

Quick Answer

Open the Advanced Editor. Look at the line immediately before the in statement and delete the comma at the end of that line. In Power Query M-code, every transformation step in the let block must end with a comma except the final step right before in.


The Anatomy of the Comma Rule in Power Query

Power Query uses commas strictly as item separators within lists, records, function argument lists, and the step chain inside a let block. Unlike languages like JavaScript or Python, M does not permit trailing commas before structural closures.

Here is the structural framework:

let
    Step1 = ...,
    Step2 = ...,
    Step3 = ...   // <-- NO COMMA ALLOWED HERE
in
    Step3

When you manually add, remove, or rearrange steps inside the Advanced Editor, a trailing comma on the last line tells the M parser to anticipate another step assignment. Finding in instead causes it to throw Expression.Error: There is an extra comma in the query code or an equivalent syntax break error.


Common Scenarios Where This Error Occurs

1. Trailing Comma Before the in Keyword

This is the most common trigger. It frequently happens when deleting the final step of a query:

  • Broken Code: let Source = Sql.Database("Server01", "FinanceDB"), #"Filtered Rows" = Table.SelectRows(Source, each [Year] = 2024), in #"Filtered Rows" The comma after [Year] = 2024) is illegal because no other step definition follows it inside the let block.
  • Corrected Code: let Source = Sql.Database("Server01", "FinanceDB"), #"Filtered Rows" = Table.SelectRows(Source, each [Year] = 2024) in #"Filtered Rows"

2. Extra Comma Inside Function Argument Lists

If you manually construct functions such as Table.TransformColumnTypes or Table.AddColumn, an accidental double comma or trailing comma inside the argument list will produce this error:

  • Faulty Code:
    The double comma ,, creates an empty argument slot that fails parsing. Remove the duplicated separator. #"Changed Type" = Table.TransformColumnTypes(Source, {{"ID", Int64.Type},, {"Date", type date}})

3. Trailing Comma in Record Syntax

Records in M are enclosed in square brackets [...]. If you leave a trailing comma after the last field, the parser rejects the block:

  • Faulty Code: Source = Csv.Document(File.Contents("C:\Data.csv"), [Delimiter=",", Encoding=1252,])
  • Corrected Code: Source = Csv.Document(File.Contents("C:\Data.csv"), [Delimiter=",", Encoding=1252])

4. Trailing Comma in List Syntax

Lists are enclosed in curly braces {...}. Nested lists (commonly used for multi-column transforms and renaming) fail if a closing brace is preceded by a comma:

  • Faulty Code: #"Renamed Columns" = Table.RenameColumns(Source, {{"OldName", "NewName"},})
  • Corrected Code: #"Renamed Columns" = Table.RenameColumns(Source, {{"OldName", "NewName"}})

How to Isolate the Extra Comma

  1. Open the Advanced Editor from the Home tab.
  2. Look at the bottom status bar inside the Advanced Editor window. Power Query displays a syntax status message:
    • If there is an error, it provides a line and column indicator: e.g., “Token Comma expected” or “Syntax error: Extra comma found at line X, column Y.”
  3. Navigate directly to that line number. If the error points to the line containing in, the extra comma is situated at the very end of the preceding step.
  4. Delete the superfluous comma.
  5. Confirm the status message at the bottom displays: “No syntax errors have been detected.”
  6. Click Done.

If cleaning up punctuation still leaves your query failing due to missing steps or bad parameters, see Expression.Error: The parameter is incorrect (Function call mismatches) to review function argument structure.