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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How can I subtract one date from another in the same column?

willstonehal_0-1683817177041.png

 

Here is a sample of what my data looks like in Power BI. I need to create a new column that subtracts the date from the previous row, and I need to do this for thousands of IDs. How can I accomplish this?

 

2 REPLIES 2
Kishore_KVN
Super User
Super User

First Create a Date Lookup Column and then create difference:

Dax for those two columns looks as below:

Date Lookup = LOOKUPVALUE('Dates Difference'[Dates],'Dates Difference'[Index],'Dates Difference'[Index]-1)
Dates Diff = DATEDIFF('Dates Difference'[Date Lookup],'Dates Difference'[Dates],DAY)

 

Result sample looks as below:

Kishore_KVN_0-1683818098395.png

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

 

 

Greg_Deckler
Community Champion
Community Champion

@Anonymous 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/339586.
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



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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors