Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
DBATTIN
Frequent Visitor

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?

1 ACCEPTED SOLUTION

@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])))




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

6 REPLIES 6
PattemManohar
Community Champion
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]))) 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




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

@DBATTIN Please use DateTime.Date(DateTime.LocalNow())





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@PattemManoharthe formula is now

 

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

 

This is now showing no syntax errors but returns an error value in the custom column. Have I done something 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])))




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@PattemManoharthank you thats brilliant Smiley Happy

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors