cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User I
Super User I

New to "M": help needed with Syntax Error

Hello,

 

I am new to Power Bi, and I'm trying to create a calendar table using M code from a book. The code reads like this:

 

= let
ChangedType = Table.TransformColumnTypes(Campañas,{{"FechaEmisión", type date}}),
MaxDate = Record.Field(Table.Max(ChangedType,"FechaEmisión"),"FechaEmisión"),
MinDate = Record.Field(Table.Min(ChangedType,"FechaEmisión"),"FechaEmisión"),
DaysElapsed = Number.From(MaxDate-MindDate),
DateList = List.Dates(MindDate, DaysElapsed+1,Duration.From(1)),
RawDatesTable = Table.FromList(DatesList,Splitter.SplitByNothing(),
{"Día"}, null, ExtraValues.Error),
ChangedType1 = Table.TransformColumnTypes(RawDatesTable,{{"Día",type date}}),
InsertedMonth = Table.AddColumn(ChangedType1,"Día", each Date.Day([Día]), type number),
InsertedMonth = Table.AddColumn(InsertedDay,"Mes", each Date.Month([Día]), type number),
InsertedYear = Table.AddColumn(InsertedMonth,"Año", each Date.Year([Día]), type number),
In
InsertedYear

 

Which asks for a "=" after the In in the penultimate line (no = sign in the code I'm copying from a book...). When I add an = sign,

as in:

In =

InsertedYear

it then says I need a token "In"...

 

Which suggests that the original code is incomplete?

 

Any help is very much appreciated!

Thank you!





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: New to "M": help needed with Syntax Error

There are various errors in your code, like

  • MinDate -> MindDate
  • DateList -> DatesList
  • 2x InsertedMonth
  • 2x Día
  • and maybe others

Below adjusted code that is working.

As your code is based on a table Campañas that I don't have, I just created a table.

 

let
//    ChangedType = Table.TransformColumnTypes(Campañas,{{"FechaEmisión", type date}}),
    ChangedType = #table(type table[FechaEmisión = date],{{#date(2017,1,1)},{#date(2017,12,31)}}),
    MaxDate = Record.Field(Table.Max(ChangedType,"FechaEmisión"),"FechaEmisión"),
    MinDate = Record.Field(Table.Min(ChangedType,"FechaEmisión"),"FechaEmisión"),
    DaysElapsed = Number.From(MaxDate-MinDate),
    DateList = List.Dates(MinDate, DaysElapsed+1,Duration.From(1)),
    RawDatesTable = Table.FromList(DateList,Splitter.SplitByNothing(),
            {"Fecha"}, null, ExtraValues.Error),
    ChangedType1 = Table.TransformColumnTypes(RawDatesTable,{{"Fecha",type date}}),
    InsertedDay = Table.AddColumn(ChangedType1,"Día", each Date.Day([Fecha]), type number),
    InsertedMonth = Table.AddColumn(InsertedDay,"Mes", each Date.Month([Fecha]), type number),
    InsertedYear = Table.AddColumn(InsertedMonth,"Año", each Date.Year([Fecha]), type number)
in
    InsertedYear
Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: New to "M": help needed with Syntax Error

There are various errors in your code, like

  • MinDate -> MindDate
  • DateList -> DatesList
  • 2x InsertedMonth
  • 2x Día
  • and maybe others

Below adjusted code that is working.

As your code is based on a table Campañas that I don't have, I just created a table.

 

let
//    ChangedType = Table.TransformColumnTypes(Campañas,{{"FechaEmisión", type date}}),
    ChangedType = #table(type table[FechaEmisión = date],{{#date(2017,1,1)},{#date(2017,12,31)}}),
    MaxDate = Record.Field(Table.Max(ChangedType,"FechaEmisión"),"FechaEmisión"),
    MinDate = Record.Field(Table.Min(ChangedType,"FechaEmisión"),"FechaEmisión"),
    DaysElapsed = Number.From(MaxDate-MinDate),
    DateList = List.Dates(MinDate, DaysElapsed+1,Duration.From(1)),
    RawDatesTable = Table.FromList(DateList,Splitter.SplitByNothing(),
            {"Fecha"}, null, ExtraValues.Error),
    ChangedType1 = Table.TransformColumnTypes(RawDatesTable,{{"Fecha",type date}}),
    InsertedDay = Table.AddColumn(ChangedType1,"Día", each Date.Day([Fecha]), type number),
    InsertedMonth = Table.AddColumn(InsertedDay,"Mes", each Date.Month([Fecha]), type number),
    InsertedYear = Table.AddColumn(InsertedMonth,"Año", each Date.Year([Fecha]), type number)
in
    InsertedYear
Specializing in Power Query Formula Language (M)

View solution in original post

Highlighted
Super User I
Super User I

Re: New to "M": help needed with Syntax Error

@MarcelBeug

 

Marcel,

 

Thank you so much for your help!!

You, Sir, are a star!

 

Best regards,

 

Paul.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors