Forum Discussion
Calculated Column - time between events in different rows
- 8 years ago
Hi jpurcell
These Calculated Columns will also give you desired results
First an Index Column
Index = IF ( OR ( TableName[EventType] = "Save", TableName[EventType] = "Open" ), RANKX ( FILTER ( ALL ( TableName ), OR ( TableName[EventType] = "Save", TableName[EventType] = "Open" ) && TableName[UserID] = EARLIER ( TableName[UserID] ) ), TableName[DateTime], , asc ) )Now the TimeSinceLastSave
Time since last save = VAR Previoustime = CALCULATE ( VALUES ( TableName[DateTime] ), FILTER ( ALLEXCEPT ( TableName, TableName[UserID] ), TableName[Index] = EARLIER ( TableName[Index] ) - 1 ) ) RETURN IF ( NOT ( ISBLANK ( TableName[Index] ) ) && TableName[EventType] = "Save", DATEDIFF ( Previoustime, TableName[DateTime], MINUTE ) )
Hi jpurcell
I think this calculated table might be close
New Table =
VAR SelfJoin =
FILTER(
CROSSJOIN(
'Events',
SELECTCOLUMNS(
FILTER('Events', [EventType] in {"Save","Open"}),
"xUserID",[UserID],
"xDateTime",[DateTime]
)
),
[xDateTime] < [DateTime] &&
[UserID] = [xUserID]
)
VAR LastPurchases =
GROUPBY(
SelfJoin,
'Events'[UserID],
Events[DateTime],
"Last DateTime",MAXX(
CURRENTGROUP(),
[xDateTime]
)
)
RETURN
ADDCOLUMNS(
NATURALLEFTOUTERJOIN('Events', LastPurchases),
"Days since last purchase" , IF('Events'[EventType]="Save" , DATEDIFF([Last DateTime],[DateTime],MINUTE),BLANK())
)- Zubair_Muhammad8 years agoCommunity Champion
Hi jpurcell
These Calculated Columns will also give you desired results
First an Index Column
Index = IF ( OR ( TableName[EventType] = "Save", TableName[EventType] = "Open" ), RANKX ( FILTER ( ALL ( TableName ), OR ( TableName[EventType] = "Save", TableName[EventType] = "Open" ) && TableName[UserID] = EARLIER ( TableName[UserID] ) ), TableName[DateTime], , asc ) )Now the TimeSinceLastSave
Time since last save = VAR Previoustime = CALCULATE ( VALUES ( TableName[DateTime] ), FILTER ( ALLEXCEPT ( TableName, TableName[UserID] ), TableName[Index] = EARLIER ( TableName[Index] ) - 1 ) ) RETURN IF ( NOT ( ISBLANK ( TableName[Index] ) ) && TableName[EventType] = "Save", DATEDIFF ( Previoustime, TableName[DateTime], MINUTE ) )- Zubair_Muhammad8 years agoCommunity Champion
That was quite ingenious .....Champ Phil_Seamark :smileyhappy:
- sirros_iot8 years agoHelper III
Can I have this results only using measures?
- Anonymous5 years agoNot applicable
Hi all
I tried this formula on my situation because it looks like the same goal, but when adapting the formula it only works partly. The strange thing is that once in a while it actually calculates the time between the events. (in the table shown below It only calculated the last event) .
My situation is show below. I want to calculate the time between when an event occurs ‘’Gekomen’’ and when the events disappears ‘’Gegaan’’, shown in the Status row. The Events have an ID which is connected by an type of event, so it can occur multiple times, I want to know the time between the status (gegaan & gekomen). (the difficult part is that all the values are appearing trough each other and the events can appear and disappear at the same time, also the events can happen multiple times in a short time.
I hope you can help me!
Status Date and Time ID Index Duration
Gegaan 1-2-2021 09:34 10 7
Gegaan 1-2-2021 09:34 637 7
Gegaan 1-2-2021 09:34 641 3
Gegaan 1-2-2021 09:34 641 3
Gegaan 1-2-2021 09:35 637 9
Gegaan 1-2-2021 09:35 10 9
Gegaan 1-2-2021 09:37 635 1
Gegaan 1-2-2021 09:37 626 3
Gekomen 1-2-2021 09:37 635 1
Gekomen 1-2-2021 09:37 635 1
Gegaan 1-2-2021 09:37 635 1
Gegaan 1-2-2021 09:37 626 3
Gekomen 1-2-2021 09:37 655 1
Gegaan 1-2-2021 09:37 655 1
Gekomen 1-2-2021 09:38 656 1
Gegaan 1-2-2021 09:39 656 2 1
- jpurcell8 years agoAdvocate I
Thanks for the help! Both solutions worked perfectly. I loved the simplicity of the table, but I'm going to use the columns so I don't have duplicate data in my report.