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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kanikasharma123
Frequent Visitor

Difference between rows and category wise sum

I want to get the difference in time of two rows between out and in and then sum the differences for each category
For example: I have the following columns- ECN_ID, Date, Time, In/Out

I want to create another column called time difference that gives the difference between the rows

kanikasharma123_0-1715596610703.png

 

The time difference between:
out and in for ECN = 2 and date 5/10/24 is 10 mins, then 1 hour respectively so total = 01:10:00
for ECN=3 and date 5/10/24, first difference is of 5 mins, then 20 mins and then 25 mins so total becomes 00:50:00,
and for ECN=3 and date 6/10/24, first difference is of 5 mins, then 20 mins, then 25 and then 30  mins so total becomes 01:00:00

 

How to achieve this? Thanks in advance!

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@kanikasharma123 

you can create a column

 

Time difference =
VAR _last=maxx(FILTER('Table','Table'[ECN_ID]=EARLIER('Table'[ECN_ID])&&'Table'[date]=EARLIER('Table'[date])&&'Table'[Time]<EARLIER('Table'[Time])&&'Table'[In/Out]="Out"),'Table'[Time])
return if('Table'[In/Out]="In",'Table'[Time]-_last)
11.png
 
then create a measure
Measure = sum('Table'[Time difference])
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

1 REPLY 1
ryan_mayu
Super User
Super User

@kanikasharma123 

you can create a column

 

Time difference =
VAR _last=maxx(FILTER('Table','Table'[ECN_ID]=EARLIER('Table'[ECN_ID])&&'Table'[date]=EARLIER('Table'[date])&&'Table'[Time]<EARLIER('Table'[Time])&&'Table'[In/Out]="Out"),'Table'[Time])
return if('Table'[In/Out]="In",'Table'[Time]-_last)
11.png
 
then create a measure
Measure = sum('Table'[Time difference])
12.PNG
 
pls see the attachment below

 





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

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.