Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Token In Expected - Syntax error

Hello Guys,

 

While writing the below code I'm getting error like Token In Expected. In my query I'm having 3 times Let and only 2 IN's, I'm confused where to place the 3rd In. I have removed my work related details and included with XXXXXXXX.

 

Note: Here I'm facing problem as I have included the exception handler highlighted in bold.

 

let AnalyticsQuery =
let Source = Json.Document(XXXXXXXXXXXXXXXXXXXX),
TypeMap = #table(
{ "AnalyticsTypes", "Type" },
{
{ "string", Text.Type },
{ "int", Int32.Type },
{ "long", Int64.Type },
{ "real", Double.Type },
{ "timespan", Duration.Type },
{ "datetime", DateTimeZone.Type },
{ "bool", Logical.Type },
{ "guid", Text.Type },
{ "dynamic", Text.Type }
}),
Exception = Source[Exceptions]?{0}?,
Result = if (Exception <> null) then
error Exception
else
let
DataTable = Source[tables]{0},
Columns = Table.FromRecords(DataTable[columns]),
ColumnsWithType = Table.Join(Columns, {"type"}, TypeMap , {"AnalyticsTypes"}),
Rows = Table.FromRows(DataTable[rows], Columns[name]),
Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => { c{0}, c{3}}))
in
Table
in AnalyticsQuery

 

 

 

 

Thanks,

AnandKali

3 REPLIES 3
edhans
Super User
Super User

I don't think you need another in, I think you need one less let.

remove the let before Source.

let AnalyticsQuery =
    Source = Json.Document(XXXXXXXXXXXXXXXXXXXX),
        TypeMap = 
            #table(
                { "AnalyticsTypes", "Type" },
                {
                { "string", Text.Type },
                { "int", Int32.Type },
                { "long", Int64.Type },
                { "real", Double.Type },
                { "timespan", Duration.Type },
                { "datetime", DateTimeZone.Type },
                { "bool", Logical.Type },
                { "guid", Text.Type },
                { "dynamic", Text.Type }
                }
            ),
        Exception = Source[Exceptions]?{0}?,
    Result = if (Exception <> null) then
        error Exception
        else
            let
                DataTable = Source[tables]{0},
                Columns = Table.FromRecords(DataTable[columns]),
                ColumnsWithType = Table.Join(Columns, {"type"}, TypeMap , {"AnalyticsTypes"}),
                Rows = Table.FromRows(DataTable[rows], Columns[name]),
                Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => { c{0}, c{3}}))
            in
                Table
in AnalyticsQuery

Also, always try to indent your code. Makes it much easier to read and see where nested let's, functions and other things are to make it easier to troubleshoot. Power Query doesn't need it, but for sure this human does. 😁



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Hi Edhans,

 

When I removed the let before sourece I'm getting error like The name 'Source' wasn't recognized. Make sure it's spelled correctly.

 

Thanks,

AnandaKali

What row is that happening on?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.