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
Vegonzalez
Frequent Visitor

Compare date to previous rows in new column

Hello,

I am working on response data date/times and trying to calculate when a unit (each row has separate unit data) is dispatched before a unit already in service clears the call using the Dispatch At date/time and Clear At date/time from the previous row.  I want the difference in time, if there is an overlap, in seconds in the new column.

Thanks!Units Busy At Same TimeUnits Busy At Same Time

   

 

1 ACCEPTED SOLUTION

@Vegonzalez 

you can create an index column in PQ

 

11.PNG

 

then use DAX to create a column

 

Column =
var _clear=maxx(FILTER('2024 Calls DS (5)','2024 Calls DS (5)'[Index]=EARLIER('2024 Calls DS (5)'[Index])+1),'2024 Calls DS (5)'[Clear At])
return if(ISBLANK(_clear),0,if('2024 Calls DS (5)'[Dispatch At]<_clear,(_clear-'2024 Calls DS (5)'[Dispatch At])*86400,0))
 
12.PNG
 
pls see the attachment below




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

Proud to be a Super User!




View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Vegonzalez ,

 

Thanks ryan_mayu  for the quick reply and solution. I have some other ideas to add:
You can use the DATEDIFF function to calculate the difference between two dates.

(1) Create an index column in Power Query.

(2) Create a column in Power BI Desktop.

Column = 
var _clear=CALCULATE(MAX('2024 Calls DS (5)'[Clear At]),FILTER('2024 Calls DS (5)','2024 Calls DS (5)'[Index]=EARLIER('2024 Calls DS (5)'[Index])+1))
RETURN IF(ISBLANK(_clear),0,IF('2024 Calls DS (5)'[Dispatch At]<_clear,DATEDIFF('2024 Calls DS (5)'[Dispatch At],_clear,SECOND),0))

 

vtangjiemsft_0-1733379520517.png

Best Regards,

Neeko Tang

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

ryan_mayu
Super User
Super User

cuold you pls provide some sample data(not the screenshot) and the expected output?





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

Proud to be a Super User!




Excel File attached as a lot of the data is private.  Expected output in Unit Busy at Same Time column.

File at https://www.dropbox.com/scl/fi/r9cymlrjmatf6hia26vsk/Report-Example.xlsx?rlkey=8alkavwl1o0235gjp1n48...

 

Thanks!

@Vegonzalez 

you can create an index column in PQ

 

11.PNG

 

then use DAX to create a column

 

Column =
var _clear=maxx(FILTER('2024 Calls DS (5)','2024 Calls DS (5)'[Index]=EARLIER('2024 Calls DS (5)'[Index])+1),'2024 Calls DS (5)'[Clear At])
return if(ISBLANK(_clear),0,if('2024 Calls DS (5)'[Dispatch At]<_clear,(_clear-'2024 Calls DS (5)'[Dispatch At])*86400,0))
 
12.PNG
 
pls see the attachment below




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

Proud to be a Super User!




Thanks.  That solution worked great.

you are welcome





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

Proud to be a Super User!




sergej_og
Super User
Super User

Hey @Vegonzalez ,
you can do a kind of approach in PQ or in DAX as well.
PQ: You can merge the data with itself. Doublicate the table.
I guess your data is already sorted properly.
If yes, you can provide an index to your data starting with 0.
Then (the dublicated table) provide an index starting with 1.
--> Merge the tables depending on index (it is a unique number). Make your calculation and remove useless columns.

DAX: Provide an index (maybe you already have a unique ID).
With this index you can use e.g. the WINDOW function.

Maybe you got the idea behind the post.

Regards.

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