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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors