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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
JovieZ
New Member

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 dates and I need to display the date difference in the report. How should I do this? 

Thanks.

 

For example, for the two rows in the following screenshot, I only need to calculate the date difference of the second row (5/12/2024-5/8/2024). 

 

JovieZ_0-1720349637861.png

 

1 ACCEPTED SOLUTION

Hi @JovieZ ,

 

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

 

DataNinja777_0-1720352596439.png

I attach a modified pbix file as an example. 

Best regards,

View solution in original post

4 REPLIES 4
DataNinja777
Super User
Super User

Hi @JovieZ ,

 

There are many ways to achive your required output and one of them is by writing a calculated column like below:

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

 

DataNinja777_0-1720351306340.png

I attach an example pbix file.  

Best regards,

 

Hi @DataNinja777 ,

 

Thanks for your quick response.

Sorry for my previous unclear description. The text content in the Date 2 column might not only be "pending". It could also be a variety of other text contents. How should I write the expression?

Hi @JovieZ ,

 

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

 

DataNinja777_0-1720352596439.png

I attach a modified pbix file as an example. 

Best regards,

foodd
Community Champion
Community Champion

Hello @JovieZ, and thank you for sharing your question with other members of the Community Forum who are supportive.   Please remember to adhere to the decorum of the Community Forum when asking a question.

Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied.

 

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.  Proud to be a Super User!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.