Forum Discussion

TIGER8855's avatar
TIGER8855
Helper I
3 years ago
Solved

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)

  • 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


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

    Hopefully this provides what you are looking for.

    Regards,
    Tom

4 Replies

    • TIGER8855's avatar
      TIGER8855
      Helper I

      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.

      • TomMartens's avatar
        TomMartens
        Super User

        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


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

        Hopefully this provides what you are looking for.

        Regards,
        Tom