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
jobf
Helper II
Helper II

Difference between dates in the same column

I need a measure or column that calculates the difference between the most recent date and the start date of a company's production. For example:

BranchDate
401/01/2025
401/05/2025
501/02/2025
501/10/2025
401/20/2025
601/03/2025
501/15/2025
601/05/2025

 

In the above case, I need the difference between the most recent and oldest dates for each branch. For example, for branch 4, the result should be 19.

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @jobf - You can create a below measure to find the date diff. For each branch as per given scenerio

 

 

 

 

 

Date Difference = 

VAR MinDate = CALCULATE(MIN('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))

VAR MaxDate = CALCULATE(MAX('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))

RETURN

DATEDIFF(MinDate, MaxDate, DAY)

 

Hope this helps





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Royel
Super User
Super User

Hi @jobf  Here is another simple calculated column for your days difference 

Days Difference = 
VAR MinDate = CALCULATE(MIN('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))
VAR MaxDate = CALCULATE(MAX('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))
RETURN 
(MaxDate - MinDate) * 1.0

Results: 

Royel_1-1758138022902.png

Find this helpful? ✔ Give a Kudo • Mark as Solution – help others too!

 

rajendraongole1
Super User
Super User

Hi @jobf - You can create a below measure to find the date diff. For each branch as per given scenerio

 

 

 

 

 

Date Difference = 

VAR MinDate = CALCULATE(MIN('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))

VAR MaxDate = CALCULATE(MAX('Table'[Date]), ALLEXCEPT('Table', 'Table'[Branch]))

RETURN

DATEDIFF(MinDate, MaxDate, DAY)

 

Hope this helps





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Greg_Deckler
Community Champion
Community Champion

@jobf In your case this should be:

Measure =
  VAR __Branch = MAX( 'Table'[Branch] )
  VAR __MaxDate = MAXX( FILTER( ALL( 'Table' ), [Branch] = __Branch ), [Date] )
  VAR __MinDate = MINX( FILTER( ALL( 'Table' ), [Branch] = __Branch ), [Date] )
  VAR __Result = ( __MaxDate - __MinDate ) * 1.
RETURN
  __Result

 

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
 ( __Current - __Previous ) * 1.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.