Expression.SyntaxError: Token Comma expected
By Tahir Nas · Examples run in our simulator · Updated
Expression.SyntaxError: Token Comma expected.
The code isn't valid M, so nothing runs. Most often a comma is missing between two steps of a let, or between list or record items. The editor points at the token after the gap.
Common causes
- Missing comma at the end of a step line in the Advanced Editor.
- A comma after the last step, just before in (the opposite mistake gives a similar error).
- Unbalanced brackets or quotes earlier on the line.
How to fix it
- Every step except the last ends with a comma.
- Check the line just above the one the editor highlights.
- Format the query (one step per line) so a missing comma stands out.
Find the step that fails
- Open the query in the Power Query editor (Excel: Data → Queries & Connections → Edit; Power BI Desktop: Transform data).
- Click the steps in Applied Steps from the top. The first step that shows the error is where it starts; later steps only repeat it.
- Read that step's formula in the formula bar (View → Formula Bar if it's hidden) and compare it with the columns and values the previous step produced.
Minimal example
Raises the error:
let Source = 1 Next = Source + 1 in NextFixed:
let Source = 1, Next = Source + 1 in NextBoth snippets are run by the Power Query Exercises simulator on every build: the first must raise Expression.SyntaxError, the second must run.
Practise avoiding it
- intermediate~9 minPro
Build a one-row summary table in M (kite shop)
Write a let expression that computes order count, total quantity and the largest unit price, returned as a one-row table.
- intermediate~9 minPro
Build a calendar from the first to the last order date (kite shop)
Create a table with one row for every day from the earliest to the latest order date, including days with no orders.
- beginner~6 minPro
Turn a settings object into a Name/Value table (report config)
A JSON settings file is a single object. List its settings as rows with Name and Value columns.
- intermediate~7 minPro
Find customers who ordered in January but not in February (kite shop)
Compare the customer lists of two months and return the customers who didn't come back.
Related lessons
- Read the M behind the Applied Steps
- Identifiers, quoted names, escapes and comments
- M basics: let, records and lists