Forum Discussion

DBATTIN's avatar
DBATTIN
Frequent Visitor
7 years ago
Solved

DATEDIFF Not Working in Custom Column

I am tyring to add the column as follows

= Table.AddColumn(#"Added Custom", "OrderAge", each DATEDIFF ([DateTimeCreated],TODAY(),DAY))

 

But I get the meaasge 

 

Expression.Error: The name 'DATEDIFF' wasn't recognized.  Make sure it's spelled correctly.

 

Can you help as I cannot see what I have done wrong?

  • DBATTIN I guess you have DateTimeCreated field as DateTime datatype which also needs to converted into Date type. So please try this...

     

    Duration.Days(Duration.From(DateTime.Date(DateTime.LocalNow())-DateTime.Date([DateTimeCreated])))

6 Replies

  • PattemManohar's avatar
    PattemManohar
    Community Champion

    DBATTIN You are trying to use both M-Language and DAX at one place and that's the reason for error. DATEDIFF is available in DAX but not in Power Query Editor.

     

    If you want to achieve DATEDIFF in Power Query Editor then use Duration.Days(Duration.From([EndDate]-[StartDate]))) 

    • DBATTIN's avatar
      DBATTIN
      Frequent Visitor

      PattemManoharIt now will not recognise the funtion Today() is that for the same reason? If so what function do I need to use for Today please?