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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
adeptus2008
Frequent Visitor

Time difference between rows grouped by value

Hi there, 

 

I have a table like that:

account_idorders_idorders_cdateorders_expdatesolution
218966107373222.05.201822.05.2019new
281343109969430.11.201830.11.2019new
326276112503230.01.201923.01.2020new
218966128579808.01.202008.01.2021update
326276129340323.01.202023.01.2021update
281343129635229.01.202012.04.2021update

I want to calculate date difference in days, between [orders_cdate] and [orders_expdate] of previous order within the group of unique account_id. How can I handle this? Thanks for any ideas.

My desrired table with calculated column would be

account_idorders_idorders_cdateorders_expdatesolutionday_diff
218966107373222.05.201822.05.2019new0
281343109969430.11.201830.11.2019new0
326276112503230.01.201923.01.2020new0
218966128579808.01.202008.01.2021update-231
326276129340323.01.202023.01.2021update0
281343129635229.01.202012.04.2021update-60
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Try. I think you want the second one.

date diff orders_cdate= datediff(table[orders_cdate],maxx(filter(table,table[account_id] =earlier(table[account_id]) && table[orders_id] 
							<earlier(table[orders_id])),table[	orders_cdate]),DAY)
							
date diff orders_cdate vs orders_expdate= datediff(table[orders_cdate],maxx(filter(table,table[account_id] =earlier(table[account_id]) && table[orders_id] 
							<earlier(table[orders_id])),table[orders_expdate]),DAY)

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

Try. I think you want the second one.

date diff orders_cdate= datediff(table[orders_cdate],maxx(filter(table,table[account_id] =earlier(table[account_id]) && table[orders_id] 
							<earlier(table[orders_id])),table[	orders_cdate]),DAY)
							
date diff orders_cdate vs orders_expdate= datediff(table[orders_cdate],maxx(filter(table,table[account_id] =earlier(table[account_id]) && table[orders_id] 
							<earlier(table[orders_id])),table[orders_expdate]),DAY)

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak It works great! Thank you!

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.

Top Solution Authors