cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

Sintaxis de fecha MCode - Mensaje de error

Estoy recibiendo un error, pero no sé cómo solucionarlo. El error procede de la fila "IfStatement".

Error:Expression.Error: No se reconoció el nombre 'DateTime.Month'. Asegúrate de que esté escrito correctamente.

let
    Source = Sql.Database(".net", "database", [Query="select *  from [dbo].[TableImUsing]  where substring([TableColumnName], 1, 3) = 'XS ' and [Status] = 'Active' and [OtherStatus] in ('Pun')"]),
    #"Added Prefix" = Table.TransformColumns(Source, {{"Column2", each "XS" & _, type text}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Prefix",{{"DAte2", type date}, {"Date1", type date}}),
    #"IfStatement"  = Table.SelectRows(#"Changed Type", if DateTime.Month(DateTime.LocalNow()) >= 8 then [Date1] > DateTime.Date(Date.Year(DateTime.LocalNow()), 8, 1) else [Date1] > DateTime.Date(DateTime.Year(Date.LocalNow())-1, 8, 1))
in
    #"IfStatement"

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Terminé dividiendo esto en varias líneas con el fin de simplificar lo que estoy tratando de llegar a.

Esto es lo que funcionó:

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Current Month Number", each Date.Month(DateTime.LocalNow())),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Current Year", each #date(Date.Year(DateTime.LocalNow()), 8, 1)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Prior Year", each #date(Date.Year(DateTime.LocalNow())-1, 8, 1)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom2", "FilterDate", each if [Current Month Number] >= 8 then [Current Year] else [Prior Year]),
    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each [Date1] >= [FilterDate])
in
    #"Filtered Rows"

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Terminé dividiendo esto en varias líneas con el fin de simplificar lo que estoy tratando de llegar a.

Esto es lo que funcionó:

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Current Month Number", each Date.Month(DateTime.LocalNow())),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Current Year", each #date(Date.Year(DateTime.LocalNow()), 8, 1)),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Prior Year", each #date(Date.Year(DateTime.LocalNow())-1, 8, 1)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom2", "FilterDate", each if [Current Month Number] >= 8 then [Current Year] else [Prior Year]),
    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each [Date1] >= [FilterDate])
in
    #"Filtered Rows"

View solution in original post

Syndicate_Admin
Administrator
Administrator

Todavía estoy recibiendo un error, aunque ahora es diferente:

Expression.Error: hay un identificador desconocido. ¿Utilizó la abreviatura [campo] para un _[field] fuera de una expresión de 'cada uno'?

let
    Source = Sql.Database(".net", "database", [Query="select *  from [dbo].[myTable]  where substring([Campaign Name], 1, 3) = 'XS ' and [Status] = 'Active' and [OtherStatus] in ('Pun')"]),
    #"Added Prefix" = Table.TransformColumns(Source, {{"ColumnA", each "XS" & _, type text}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Prefix",{{"Date2", type date}, {"Date1", type date}}),
    #"IfStatement"  = Table.SelectRows(#"Changed Type", if Date.Month( DateTime.Date( DateTime.LocalNow() )) >= 8 then [Date1] > DateTime.Date( Date.Year( DateTime.Date( DateTime.LocalNow())), 8, 1) else [Date1] > DateTime.Date(                                                                             Date.Year(DateTime.Date(DateTime.LocalNow()))-1, 8, 1))
in
    #"IfStatement"

Syndicate_Admin
Administrator
Administrator

@GTPowerBIUser , En realidad la fecha tiene mes y año, no fecha y hora.

Ejemplo

Fecha.Mes(DateTime.Date(DateTime.LocalNow()))

corregir otros

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.