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
PaulDBrown
Community Champion
Community Champion

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
MarcelBeug
Community Champion
Community Champion

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
MarcelBeug
Community Champion
Community Champion

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)

@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
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.