Forum Discussion
GKJARC
2 years agoResolver I
Get previous row's value
Hi all,
I'm looking for a way get the timestamp of the previous row onto the current row. So that when they're on the same row, I can calculate the time difference for each user.
Example:
| UserID | Timestamp | Previous row's timestamp | Calculated time difference (mm:ss) |
| 001 | 14:50:00 | ||
| 001 | 14:52:30 | 14:50:00 | 02:30 |
| 001 | 14:55:30 | 14:52:30 | 03:00 |
| 001 | 14:58:10 | 14:55:30 | 02:40 |
| 002 | 08:58:10 | ||
| 002 | 09:00:00 | 08:58:10 | 01:50 |
| 002 | 09:01:00 | 09:00:00 | 01:00 |
| 002 | 09:01:20 | 09:01:00 | 00:20 |
So the first and second column is an existing column in the report.
The third column is what I need.
The fourth column I can manage once I have the third column in place.
How to create the second column using DAX, without using the Power Query Editor?
Any help would be appreciated, thanks!
Hi,
Please check the below picture and the attached pbix file.
OFFSET function (DAX) - DAX | Microsoft Learn
Previous CC = SELECTCOLUMNS ( OFFSET ( -1, Data, ORDERBY ( Data[Timestamp], ASC ), , PARTITIONBY ( Data[UserID] ), MATCHBY ( Data[UserID], Data[Timestamp] ) ), Data[Timestamp] )Diff CC = IF ( NOT ISBLANK ( Data[Previous CC] ), Data[Timestamp] - Data[Previous CC] )
2 Replies
- Jihwan_KimSuper User
Hi,
Please check the below picture and the attached pbix file.
OFFSET function (DAX) - DAX | Microsoft Learn
Previous CC = SELECTCOLUMNS ( OFFSET ( -1, Data, ORDERBY ( Data[Timestamp], ASC ), , PARTITIONBY ( Data[UserID] ), MATCHBY ( Data[UserID], Data[Timestamp] ) ), Data[Timestamp] )Diff CC = IF ( NOT ISBLANK ( Data[Previous CC] ), Data[Timestamp] - Data[Previous CC] ) - GKJARCResolver I
Works great, thanks a lot!