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
TIGER8855
Helper I
Helper I

exclude text values when using DATEDIFF

I'm using DATEDIFF to find the number of days between today and dates in column however the column also has some values that are text therefore the the calculation doesn't work. 

Can anyone advise how values with text can be exluded so that the Date difference will work on the values that are dates?

 

Column = DATEDIFF(Table1[Expiry],today(),DAY)

1 ACCEPTED SOLUTION

Hey @TIGER8855

you can do this with two steps in Power Query, create a new column with this code
try Date.FromText ([maybe a Date] )
otherwise null
image.png

Then change the data type to Date
This result might look like this:
image.png

Hopefully this provides what you are looking for.

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey @TIGER8855 ,

 

this will not work because the DATEDIFF function requires the argument to be either of data type DATE or DATETIME: DATEDIFF – DAX Guide

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks @TomMartens . Do you know what is the easiest way to create a new column with just the dates and if there is text, the cell in the new column is blank? This way I can use the DATEDIFF on the new column with only the dates.

Hey @TIGER8855

you can do this with two steps in Power Query, create a new column with this code
try Date.FromText ([maybe a Date] )
otherwise null
image.png

Then change the data type to Date
This result might look like this:
image.png

Hopefully this provides what you are looking for.

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks @TomMartens. That works. My original DATEDIFF can now be used on this new column.

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.