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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jobf
Helper I
Helper I

Difference between dates in the same column

Hello. I need to create a column or measure that can calculate the difference between two dates in the same column, based on lines from other columns. For example:

 

Field  Input Application  Date
P1  INPUT1  1st01/01/2024
P2  INPUT1  1st01/05/2024
P1  INPUT1  2nd01/20/2024
P2  INPUT1  2nd01/22/2024
P1  INPUT1  3rd02/10/2024
P2  INPUT1  3rd02/11/2024
P1  INPUT2  1st02/15/2024
P2  INPUT2  1st02/15/2024
P1  INPUT2  2nd02/27/2024
P2  INPUT2  2nd02/28/2024
P1  INPUT2  3rd03/10/2024
P2  INPUT2  3rd03/11/2024
P1  INPUT3  1st03/14/2024
P2  INPUT3  1st03/16/2024
P1  INPUT3  2nd03/20/2024
P2  INPUT3  2nd03/24/2024
P1  INPUT3  3rd04/02/2024

P2

  INPUT3  3rd

04/05/2024

 

Then I would need, for example, the difference between the date of the 2nd application of INPUT3 on field P1 and the date of the 1st application of INPUT3 on field P1.  I needed to create a column or measure that calculated the difference between all the dates (days) of the same application of the same INPUT in the same field.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jobf 

 

You can add a calculated column with this formula

Duration = 
var _currentDate = 'Table (2)'[Date]
var _previousDate = CALCULATE(MAX('Table (2)'[Date]),ALLEXCEPT('Table (2)','Table (2)'[Field],'Table (2)'[  Input]),'Table (2)'[Date]<_currentDate)
return
DATEDIFF(_previousDate,_currentDate,DAY)

vjingzhanmsft_0-1719822002895.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @jobf 

 

You can add a calculated column with this formula

Duration = 
var _currentDate = 'Table (2)'[Date]
var _previousDate = CALCULATE(MAX('Table (2)'[Date]),ALLEXCEPT('Table (2)','Table (2)'[Field],'Table (2)'[  Input]),'Table (2)'[Date]<_currentDate)
return
DATEDIFF(_previousDate,_currentDate,DAY)

vjingzhanmsft_0-1719822002895.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Overall, the code worked, but an error occurred in ALLEXCEPT. "The ALLEXCEPT function expects a table reference expression for argument '4', but a string or numeric expression was used."

NaveenGandhi
Super User
Super User

Hi 

The requirement is quite confusing, But try below soltution. 

Create a column using below DAX

Key = 'Table'[Field]&'Table'[  Input]&'Table'[ Application  ]

Then create another column
Diff =

Var Date1 = CALCULATE(MAX('Table'[Date]),ALL('Table'),'Table'[Key]<EARLIER('Table'[Key]))

RETURN DATEDIFF(Date1,'Table'[Date],DAY)

Screenshot 2024-06-28 204537.png

Let me know if this is what you are expecting or share a little bit more details with sample output.

 If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!


It's kind of hard to understand, but I'll try to explain. In a field, several inputs will be applied, and these inputs will be applied more than once. I needed to calculate, somehow, the difference between these applications of this input in this specific field. In this case, the difference between the 2nd and 1st and the difference between the 3rd and 2nd.

It would be great if you can share some pictures and explain it in detail, The details you have provided is definelty for enough to resolve the problem.

Regards,

Naveen

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.