Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Calculate date difference between two columns

Hello,   I'm new to Power BI. There are two columns in Excel, each containing both dates and text. I want to import them into Power BI and only calculate the date difference of the rows containing...
  • DataNinja777's avatar
    DataNinja777
    2 years ago

    Hi Anonymous ,

     

    There are multiple ways to achive your required output even though the text descriptions have multiple variations.  My example below is based on the assumption that your text description variants do not contain "/" used in the date text. With this assumption the original calculated column can be modified as follows:

    Date Diff = 
    VAR Date2 =
        IF (
            CONTAINSSTRING ( 'Table'[Date 2], "/" ) = TRUE,
            FORMAT ( 'Table'[Date 2], "m/d/yyyy" ),
            FORMAT ( 'Table'[Date 1], "m/d/yyyy" )
        )
    RETURN
        IF ( Date2 - [Date 1] <> BLANK (), Date2 - [Date 1] )

     

    I attach a modified pbix file as an example. 

    Best regards,