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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
harshagraj
Post Partisan
Post Partisan

How to get row to row difference by Group/sort

Hello all, I need to group/sort by ModulNr and StationsNr and need the datediff in secs by row2 - row1,row3-row2. Attached the data and also screenshot. Please note I am in a direct query mode. 

Thanks upfront.

 

ModulNrStationsNrModuleStnPreStopperArrival_CExpected Result in Secs
81M8-S124-11-2020 14:26:21 
81M8-S124-11-2020 14:26:309
81M8-S124-11-2020 14:26:365
81M8-S124-11-2020 14:29:10 
71M7-S124-11-2020 14:29:26 
61M6-S124-11-2020 14:29:51 
51M5-S124-11-2020 14:30:09 
71M7-S124-11-2020 14:30:27 
61M6-S124-11-2020 14:30:45 
51M5-S124-11-2020 14:31:02 

 

now.JPG

@amitchandak @Anonymous @ryan_mayu @Anonymous @parry2k 

9 REPLIES 9
ryan_mayu
Super User
Super User

@harshagraj 

maybe you can try to create a measure

Measure = 
VAR arrive=max('Table'[PreStopperArrival_C])
VAR Previous=MAXX(FILTER(all('Table'),'Table'[ModulNr]=max('Table'[ModulNr])&&'Table'[StationsNr]=max('Table'[StationsNr])&&'Table'[PreStopperArrival_C]<arrive),'Table'[PreStopperArrival_C])
return if(ISBLANK(Previous),BLANK(),SECOND(arrive-Previous))

1.PNG





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

Proud to be a Super User!




Hello @ryan_mayu  thanks a lot. Its working perfectly. But I need to plot Barchart. X axis will have Concatenated Module Station Nr and Y axis i have to consider Avergae Carriertime.

Carriertime(Measure) = Above calculated field  minus(-) Prestoparrdiff

Prestoparrdiff(Measure)=DATEDIFF(SELECTEDVALUE(CTM_Timestamps[PreStopperArrival_C]),SELECTEDVALUE(CTM_Timestamps[DepositCarrier_C]),SECOND)
will the above calculation works with Barchart? I tried but ended up in wrong values
prs.JPG
 

@harshagraj 

I keep working on the previous sample data. you can try to create a measure

average = averagex(CTM_Timestamps,[Carriertime])

1.PNG

please see the attachment below

 





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

Proud to be a Super User!




Hello @ryan_mayu thanks a lot for the help. I just exactly did the same steps. But I am getting below error. My data size is huge actually. Every 5 seconds i get 8 records for different modules and from diff stations

harshagraj_0-1606316742506.png

 

Hi @harshagraj ,

 

Replace calculated column 'CTM_Timestamps'[Run] with a measure and try it again.

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

@harshagraj 

I seldom us direct query. can pbi display the bottom left table on your end? That table contains the same fields and measures as the chart.





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

Proud to be a Super User!




Anonymous
Not applicable

1) Why directquery 

2) What is you source

Anonymous
Not applicable

Thanks @Anonymous  but I am on Direct query mode.

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.