Forum Discussion

ansa_naz's avatar
ansa_naz
Continued Contributor
7 years ago
Solved

Keep getting "Expression.Error: We cannot apply operator < to types Date and DateTime" - please help

I have the following M code in Query Editor from power BI:   let Source = Sql.Database("DB", "DB", [CommandTimeout=#duration(0, 1, 0, 0)]), dbo_Calls = Source{[Schema="dbo",Item="Calls"]}[D...
  • Gordonlilj's avatar
    7 years ago

    Hi,

     

    You could either change the datetime column to date or the other way around.

     

    Or you could try adding DateTime.From() to the date columns.

    I don't know which one is the datetime columns so i added the function it to all of them.

    #"Filtered Rows" = Table.SelectRows(dbo_ANSAPBICalls,each DateTime.From([Completion Date])>=DateTime.From(StartDate) 
        and DateTime.From([Completion Date])<=DateTime.From(EndDate))
  • tex628's avatar
    7 years ago

    You are comparing Date format with Datetime format. Change the format from datetime to date on your start and enddate before the filterstatement and it should work fine!

    /J

  • ansa_naz's avatar
    ansa_naz
    7 years ago

    Its fixed now. I changed all Date functions to DateTime. I also amended the Filtered Rows step so it was using SelectRows from #ChangedType step, not from the original data source:

     

    let
        Source = Sql.Database("DB", "DB", [CommandTimeout=#duration(0, 1, 0, 0)]),
        dbo_Calls = Source{[Schema="dbo",Item="Calls"]}[Data],
        #"Changed Type" = Table.TransformColumnTypes(dbo_Calls,{{"Completion Date", type date}}),
        EndDate = Date.From(DateTime.FixedLocalNow()),
        StartDate = Date.AddDays(Date.AddMonths(EndDate,-6),1),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type",each DateTime.From([Completion Date])>=DateTime.From(StartDate) 
        and DateTime.From([Completion Date])<=DateTime.From(EndDate))
    in
        #"Filtered Rows"

    Thats done the trick, cheers for all the help!