Forum Discussion
Time duration between rows in same column
- 6 years ago
If you want to do this in the query rather than as a DAX column you could use a technique like the following to join to the previous row https://exceltown.com/en/tutorials/power-bi/powerbi-com-and-power-bi-desktop/power-bi-data-sources/power-query-get-value-from-previous-row/
Thanks d_gosbell and apologies for the lack of clarity
I am attempting to create a new column in the querry editor that produces a time difference/duration time based on current row to the preceeding row of the Arrival Time column after the Arrival Time column has been sorted in Ascending order.
your solution allowed me to create a time difference column by creating a new column if modelling but I can not sort the Arrival Time in Ascending order as the arrival time is sorted in Date Hierarchy format Year/Quarter/Month/Day
hi, Buster
Do you mean that you want to create it in edit queries? For you need to sort arrival time in Date Hierarchy format Year/Quarter/Month/Day in edit queries.
If so, just adjust the solution as below:
Step1:
After you sort arrival time in Date Hierarchy format Year/Quarter/Month/Day in edit queries, Then add an Index column.
Step2:
Then add a New column by this formula in modeling
Column = var _currentIndex = Table1[Index] var _previousIndex = maxx( filter(VALUES(Table1[Index]), Table1[Index] < _currentIndex), [Index]) return if (_previousIndex = 0, blank(), DATEDIFF( CALCULATE(SUM(Table1[arrival time]),FILTER(Table1,Table1[Index]=_previousIndex)), Table1[arrival time], MINUTE))
Regards,
Lin