cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
michael_knight
Post Prodigy
Post Prodigy

Date Difference Between two columns and rows

Hi,

 

I'm trying to create a formula which will display the difference between The End Date and the Start Date. This is showing how long it took to start a process after finishing one. In the case for ID 1, they finished the process and then started another one, it took 23 days to start the next process

 

 

IDStart DateEnd DateExpected Outcome
105/05/202123/05/20210
115/06/2021 23
225/03/2021 0
302/07/202106/07/20210
317/07/202120/07/202111
329/07/2021 9
409/09/2021 0
525/09/202127/09/20210
515/10/202120/10/202118

The Expected Outcome is what I manually did, I want to create that column within Power BI

 

I posted the table because I'm to upload to OneDrive etc. 

 

Thanks,

Mike

1 ACCEPTED SOLUTION

@michael_knight , Try a new column like

 

Column = var _max1 = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] <EARLIER('Table'[Start Date])),[Start Date]) 
var _max  = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] =_max1),[End Date] ) 

return if(ISBLANK(_max), BLANK(), DATEDIFF(_max,[Start Date],DAY))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

View solution in original post

6 REPLIES 6
michael_knight
Post Prodigy
Post Prodigy

Hi,

Does anyone know how I can fix the issue above?

Thanks

@michael_knight , Try a new column like

 

Column = var _max1 = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] <EARLIER('Table'[Start Date])),[Start Date]) 
var _max  = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] =_max1),[End Date] ) 

return if(ISBLANK(_max), BLANK(), DATEDIFF(_max,[Start Date],DAY))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
amitchandak
Super User
Super User

@michael_knight , a new column

new column =

var _max = maxx(filter(Table, [ID] =earlier([ID]) && [Start Date] < earlier([Start Date]) ) , [End Date])

return

if( Isblank(_max), blank(), datediff(_max, [Start Date], day))

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Hi @amitchandak 

 

Thank you for the reply. That's brilliant but one thing which I forgot to mention, if there is two processes on going, it must displace the earlier version. For example, for ID #3 

 

IDStart DateEnd DateExpected Outcome
105/05/202123/05/20210
115/06/2021 23
225/03/2021 0
302/07/202106/07/20210
317/07/202120/07/202111
329/07/2021 9
305/08/2021  
409/09/2021 0
525/09/202127/09/20210
515/10/202120/10/202118

 

There are two ongoing processes, it should only display the date difference for earliest version with the latest version being left blank

@michael_knight , Try a new column like

 

Column = var _max1 = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] <EARLIER('Table'[Start Date])),[Start Date]) 
var _max  = maxx(FILTER('Table',[ID] =EARLIER([ID]) && [Start Date] =_max1),[End Date] ) 

return if(ISBLANK(_max), BLANK(), DATEDIFF(_max,[Start Date],DAY))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

View solution in original post

Brilliant, thank you @amitchandak 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.